Plugin Switch Condition Help

Proelium_Ex_Deus

God of War... & Tinkerer
Member
Joined
Jun 22, 2016
Messages
26
Reaction score
2
First Language
English
Primarily Uses
RMMV
OK.. I'm exasperated & just burnt out. I've checked dozens of existing JS, forums, & Google searches, with nothing remotely close to what I'm looking for (how in the **** can something so simple be such a pain in the **** to find??).

All I'm trying to do is add a "switch check / condition" < e.g. if ($gameSwitches.value[x] === true) > to my plugin; where the switch must be active to draw a custom window on the screen. I've freakin' tried putting it in every place imaginable (before the main function, in the scene map, before the 'drawwindow' initializes, etc.), & I can't get it to work properly. I've managed to get the plugin to load without error a few times (placing the switch check where it makes logical sense), but when I try activating the switch ingame, I get an error. Any thoughts?
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
$gameSwitches.value is not an array, but a function. You have wrong brackets.
 

Proelium_Ex_Deus

God of War... & Tinkerer
Member
Joined
Jun 22, 2016
Messages
26
Reaction score
2
First Language
English
Primarily Uses
RMMV
Thx Poryg. I'm going nuts trying to find an answer to this prob... (even going to the CodeAcademy to review JS), & think I'm gonna have to rework this / start over. On the surface it seems logical & easy to me... but I'm also basing the logic on my knowledge of C#.... JS is a new beast to me (& among other things, the .prototype thing seems strange to me).

I think I see where I'm goofing this up, tho (outside of the pt you made of the wrong [], which I placed by mistake as I was typing the example ). I'm trying to use a switch to, more or less, "disable" the script, when, I think, that is impossible in MV (assuming it runs & saves plugin data every [x] ticks / seconds, & the absence of the data would corrupt the game &/or player save). Instead, I think I'm gonna have to find a way to just hide the window when either a defined switch or variable is active.

I've exhausted all of the ideas I have about how to do this (e.g. vid tutorials, sample scripts, etc.). Could you pt me in the right direction, Poryg (or any good Samaritan)?

Here's the script, as it currently is... (now where the heck does the "switch condition" go?, lol)

P.S. The plugin works GREAT... but there are game scenes where the clock needs to be hidden (e.g. cutscenes, lol), so that it isn't persistently visible. And for any willing to help me... plz bear with me. I'm an old school C++ & C# coder, so JS is new territory to me, & I am trying the best I can, (via my own research of the topic &/or probs I have, etc.).



Code:
(function() {

//-----------------------------------------------------------------------------
// Scene Map
//-----------------------------------------------------------------------------
var _Scene_Map_start = Scene_Map.prototype.start;
Scene_Map.prototype.start = function() {
  _Scene_Map_start.call(this);
  this.clockWindow = new DEP_WorldClock(1120, 0);
  this.addWindow(this.clockWindow);
};

var _Scene_Map_update = Scene_Map.prototype.update;
Scene_Map.prototype.update = function() {
  _Scene_Map_update.call(this);

  this.clockWindow.refresh();
};

//-----------------------------------------------------------------------------
// Clock Window
//-----------------------------------------------------------------------------
function DEP_WorldClock() {
  this.initialize.apply(this, arguments);
};

DEP_WorldClock.prototype = Object.create(Window_Base.prototype);
DEP_WorldClock.prototype.constructor = DEP_WorldClock;

DEP_WorldClock.prototype.initialize = function(x, y) {
  Window_Base.prototype.initialize.call(this, x, y, this.windowWidth(), this.windowHeight());

  this._hour = -1;
  this.refresh();
};

DEP_WorldClock.prototype.refresh = function() {
     if(this._hour != $gameVariables.value(979)) {
            this._hour = $gameVariables.value(979);
            this.contents.clear();
            this.drawIcon(35, 0, 0);
            this.drawText(this._hour + ':00', Window_Base._iconWidth + 8, 0, this.windowWidth() - (Window_Base._iconWidth + 8), 'left');
       }     
    
};

DEP_WorldClock.prototype.windowWidth = function() {
  return 160;
};

DEP_WorldClock.prototype.windowHeight = function() {
  return this.fittingHeight(1);
};

})();
 

Proelium_Ex_Deus

God of War... & Tinkerer
Member
Joined
Jun 22, 2016
Messages
26
Reaction score
2
First Language
English
Primarily Uses
RMMV
The closest (I think) that I've been able to come up with is something like:

Code:
var _Scene_Map_start = Scene_Map.prototype.start;
Scene_Map.prototype.start = function() {
  _Scene_Map_start.call(this);
  this.clockWindow = new DEP_WorldClock(1120, 0);
  this.addWindow(this.clockWindow);
     if ($gameSwitches.value(997));
          this.clockWindow.hide();
};
I've tried it, with no success... & I don't imagine I'd need an 'else' statement... but I guess I'll try that next. If it doesn't work, I'll either wait for a response, or try again later (sigh).
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
7,842
Reaction score
5,224
First Language
Dutch
Primarily Uses
RMXP
@Proelium_Ex_Deus Please don't double post (= posting right after yourself). If you want to add something, just use the 'Edit' button.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
Well, JS prototype is nothing difficult, it's just syntactic sugar for classes.
class Window {
constructor: function () {
}
foo: function () {
}
}

is the same as
function Window() {
Window.prototype.constructor = Window;
Window.prototype.foo = function () {}

As for your code, writing ifs in JS is the same as writing ifs in C# and other languages like that. If you use only one line of code, you don't need {}, but need to keep it on one line.
If you use multiple lines, you need to use {}. You'd find out easily if you had searched on how to type ifs in JS :D
Also, why do it like that? Why add a pointless window?
var _Scene_Map_start = Scene_Map.prototype.start;
Scene_Map.prototype.start = function() {
_Scene_Map_start.call(this);
if ($gameSwitches.value(997)) {
this.clockWindow = new DEP_WorldClock(1120, 0);
this.addWindow(this.clockWindow);
};
};

Btw. the trick would work just fine if you hadn't separated the if with a semicolon.
if ($gameSwitches.value(997)) this.clockWindow.hide(); is correct.
 
Last edited:

Proelium_Ex_Deus

God of War... & Tinkerer
Member
Joined
Jun 22, 2016
Messages
26
Reaction score
2
First Language
English
Primarily Uses
RMMV
@slimmmeiske2 My apologies. I didn't realize that was a forum violation (must have missed that one... sry)

@Poryg I really preesh the support man. The code is formatted like that b/c I'm still sloppy with code. My purpose for coding in the past hasn't much to do with gaming, lol... but for CAD & 3D environments, so I think I'm stumbling through this with redundancy, lol. And I DID, actually, lookup If/Else JS, & it looks like what I've worked with before... that's partly why I'm absolutely befuddled on this. lol

Anywho... I tried the if ($gameSwitches.value(997)) this.clockWindow.hide(); statement under the _Scene_Map_start, without any luck (I checked the debug console, btw, to make sure the switch was on... & it was) :blink:
So close, yet so far. Next thoughts? lol
 
Last edited:

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
Am I a fool or what?
Create an event. A normal action button triggered event. And place this this into the event's script command into some map where the clock needs to be hidden:

Code:
console.log($gameSwitches.value(997));
console.log(SceneManager._scene.clockWindow.visible);
Then open the dev tools with f8 and print the console log.
Also, just btw., when do you turn the switch on and off? Before you teleport on the map? Or after? If after, then no wonder :D
 

Proelium_Ex_Deus

God of War... & Tinkerer
Member
Joined
Jun 22, 2016
Messages
26
Reaction score
2
First Language
English
Primarily Uses
RMMV
OK man... here's what I got... (the pix always seem like they take a sec for them to load, for some reason, so bear with me plz)...

(fyi... I've tried using the "media link" several times before, with GDrive, & have never had any luck getting it to work -- edit: I may have finally got the GDrive media link to work, yays... finally, something is going right, lol)

My Script


My Map Event


The Evented Switch


Live Test (see the clock working / visible)


Live Test (console, before clicking the event switch)


Live Test (console, after clicking event switch & running console logs)

Incidentally... I'm getting weary of working on this. I've been trying to find a resolution for nearly 24 hrs straight, & I'm gonna have to take a break soon (& I know you've been working to help me for a while too, Porgy). I'd like to keep this topic open, if Poryg is willing to continue working with me on it (after I take a break for a while).
 
Last edited:

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
First Language
English
Primarily Uses
RMMV
OK I read this thread up and down, and I think you need to take a step back and define what you really want to do. You might be jumping into the details too quickly.

Do you want the window to show/hide on certain maps but not others?
Do you want the window to show/hide by on-map events?
Do you want the window to show/hide by common events?
When the window is hidden, does the time still flow?

If you can concisely explain what you are looking for (in words, not code), then it should be easy to insert conditional statements in the appropriate places.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
Well, the switch is off. And in order for the window to not be shown, you need to turn it on before you teleport to the map. So the script is working as it should, you just didn't turn the switch on.
 

Proelium_Ex_Deus

God of War... & Tinkerer
Member
Joined
Jun 22, 2016
Messages
26
Reaction score
2
First Language
English
Primarily Uses
RMMV
@Poyrg Sorry dude... you're right. I was trying to activate the $ <-- the symbol I'm used to for the word "switch" --, thinking it would make the clock appear & disappear on the spot (a "tard" moment, seeing as how I've only setup a million other switches w/ scripts & have had to have them active prior to the script doing its job... siiigh). I wasn't thinking of it in the sense of how MV processes the data. Sorry for the delay in that clicking with me, & thanks a mil.

@Aloe Guvner The time system is a separate event that flows regardless of when the clock is visible. As for the clock, it merely displays the variable I have set to my time system's hour... thus... it is being shown only for the player's convenience, since there are events in the game that are time specific, & it's nice to see the time on your main screen to avoid having to go into the menu constantly to check it (as I had it setup originally). BUT... it's not so nice to see that clock window during cutscenes & "function maps" (e.g. maps that run special events to mimic computer terminal use, etc.), so I've been trying to figure out a way to hide the window via switch, so that I can choose when it should or shouldn't be seen. Due to the battle scripts I have in place, the window does not appear in battles... so all I need is to find a working script that hides the clock when a specific switch is turned on.

Thanks a bunch guys... I'll be reposting this on the plugins page for any who wish to accomplish a similar feat (& will later inc. the time / food system I've been working on with this for others to enjoy as well). I've got no delusions of being a JS coder or anything, lol, so it'll be open to whoever wants to tinker with &/or refine it. :D

Regrettably, I can't help you guys out with JS, (lol, obviously), but if you ever need help with Arduino, 3D print, or CAD projects let me know. I can also lend a hand with audio editing / mastering /or composition. Thanks again, & have a great day!!
 
Last edited:

Aloe Guvner

Walrus
Veteran
Joined
Sep 28, 2017
Messages
1,628
Reaction score
1,115
First Language
English
Primarily Uses
RMMV
In your events to turn the window on and off you could have an Event Command script call.

So at the start of a cutscene event, hide the window:
Code:
SceneManager._scene.clockWindow.hide();
At the end of the cutscene event, show the window:
Code:
SceneManager._scene.clockWindow.show();
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c

Forum statistics

Threads
105,857
Messages
1,017,015
Members
137,563
Latest member
MinyakaAeon
Top