Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

Using a Variable to pass parameter to Script call...

Dad3353

Praised Adventurer
Good afternoon...

I've an Event on a Map which calls a Common Event. I want the Common Event to address the Self-Switch of the Caller Event. Here's a screen shot which describes the essence of what's happening...
Any advice gratefully received, thanking you in advance...
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
I'm not at my laptop so i can't check anything at the moment and its been so long I can't quite recall the proper code you need but I should be able to point you in correct location. Basically you want the common event to address the event on which it is being called. So you will need the current event id to do this, I believe this.eventId is close to what I'm thinking, not 100% sure but a quick search in MV's code base should do the trick and confirm. If this don't help ill be back at my laptop in about 4 hours and ill come back and help you some more.
 

Dad3353

Praised Adventurer
...So you will need the current event id to do this...
Indeed; I have passed the calling Event ID into a Variable. My problem is how to get that Variable's Value usable for the $gameSelfSwitch command. If I use the Event ID directly, it works, but I can't get the $gameSelfSwitch to use the Variable Value instead of the hard-wiring. All is explained in the Screenshot, I think...
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
Ah I see yes. Well my solution is very similar but you won't need a variable at all, you can just insert this._eventId directly into $gameSelfSwitch. This way works for me and you can save some variables space lol.

If you only ever need the current event id then you can completely avoid the variable, for me it seems like less of a headache but there may be a reason for you doing it that way. If so let me know and I'll try to get your way working.
JavaScript:
$gameSelfSwitches.setValue([this._mapId, this._eventId, 'A'], true);
 

Dad3353

Praised Adventurer
...
JavaScript:
$gameSelfSwitches.setValue([this._mapId, this._eventId, 'A'], true);
This is exactly what's required, with the proviso that it actually turn off the switch..! I've just spent several minutes being chased by an angry boar..! Let me explain...
We are in a forest, where these creatures abound, nonchalantly going about their business. Along comes our Hero, clumsily bumping into one. This provokes his ire, and he dashes about, chasing the Hero for 5 seconds., before returning to his strolling. With a Switch as a trigger, this works fine, except that there are over a dozen of these animals in the forest. Upsetting one sets off the whole lot in a frenzy. I decided to use the Self-Switch instead as a trigger for the Event, but need the Common Event to turn off this Self-Switch and no other. Progress, as there is no error now, but the boar now chases the Party until I step in and close the window..! Here's the unadulterated screen shots of the two Boar Events and the Common Event. Why doesn't the Self-Switch get turned off, please..?
We're so close to a solution (and about time, as I'm now puffed out with all of that being chased..!;-)

Edit: If I use 58 as Map ID and 55 as Event ID, it works just fine, so the Self-Switch remote turning off does work. It's the passing of the Event ID which is not working. I could accept hard-wiring the Map ID; that would just be a bonus for future occasions.




 
Last edited:

LTN Games

Master Mind
Resource Team
Xy$
0.01
So you just need the switch to be turned off rather than on. In my example above I set it to turn on.
JavaScript:
//This will turn the self-switch on
$gameSelfSwitches.setValue([this._mapId, this._eventId, 'A'], true);

//This will turn the self switch off
$gameSelfSwitches.setValue([this._mapId, this._eventId, 'A'], false);

//Notice the last parameter is set to false. True = on, false = off
If you already modified the script to turn off and you still get this behavior, it means there may be an issue elsewhere. My first thought would be that turning off self switch A will then make the event go back to page 1 and turn 'A' back on, so a solution is you could make another page, with self switch 'B' and instead of turning off 'A' turn on 'B'., which should direct the event to page 3.

This will turn on selfswitch B
JavaScript:
$gameSelfSwitches.setValue([this._mapId, this._eventId, 'B'], true);
Hopefully somewhere in my post you find the solution lol If not I'll go ahead and re-create the same scenario and see what I can come up with and upload a small demo for you.
 

Dad3353

Praised Adventurer
...
Hopefully somewhere in my post you find the solution lol...

'Fraid not. I tried switching On a third Page with 'B', but still no response. Again, using hard-wired '58' and '55' for MapID and Event ID respectively, it works fine, and will switch a 'B' Page with no problem. I'm certain there's nothing else messing this up (as it works with the numbers fed in directly...), and part of my raison d'être with this Project was to not use Plug-ins or scripts from others, so this is a very much 'vanilla' affair (although growing to well over sixty Maps, now...).
Incidentaly, should there be a ';' at the end of my Script command..? I've used many languages in my long past career, but never Java, and the syntactical idiosyncrasies are often where I trip up as a beginner. Thanks, in any case, for the help offered so far; as a last resort I could control this wild herd of boars (I've learned that the collective name for 'em is a 'sounder', 'passel', 'team' or ''singular'. Who knew, eh..?) with a regular, global Switch, but if better can be done..?
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
I see the issue now that I've slowed down a bit and took a better look. I assumed you were calling the common event on each event not noticing you are usinSg a switch with a parallel common event. Using this.eventId will only work properly if the event calls the common event rather than using a switch. So I came up with a different solution, which is still fairly simple, it required you to get the eventId for all events that you wan the self switches to turn off for.
Just replace the current script call with this, where eventToCheck are all the eventId's you want the selfSwitch to turn off. The mapId is obviously the mapId where all the events are, then we do a for loop to iterate through all eventId's and turn off the self switch A.
JavaScript:
// The id's of all events you want to check
var eventsToCheck = [1, 2, 3 ,4 ,5];
// The map Id the events are located
var mapId = 1;
// Just storing the length of the array in a variable
var eventsLength = eventsToCheck.length;
// Iterate through the eventId's and turn off self switch A
for(var i = 0; i < eventsLength; i++){
    $gameSelfSwitches.setValue([mapId, eventsToCheck[i], 'A'], false);
}
For me I used chickens to test it, as soon as I hit the chicken the self switch turned on then turned on the common event, after 5 seconds it turned off the self-switch and the chicken proceeding at normal. The small issue is that if you hit a chicken about 2 seconds after hitting the first one, both will turn off when that timer is up, this would have happened your way as well, I just wanted to bring it up.
If you have any questions about the script call let me know and I'll try explaining a bit more, I assume you know what a for loop is, especially if you've dabbled in other languages already. Hope this works for you :D

EDIT: Fixed typo in script call
 
Last edited:

Dad3353

Praised Adventurer
I see the issue now...
Well, if it's working for chickens, maybe I should change the sprites..?

No, lad, you've nailed it with this. I've taken the ID of each boar (visible in the status bar at bottom of screen when selected, so no great chore...) and it works just fine.
I note the calling directly from the Event, however, instead of using a Switch; if that works too (and, with your explanation, I've every reason to think it will...), I can maybe render the Common Event re-usable, without hard-wiring the calling ID's. That'll be more progress still; I had originally called the Common Event that way, but then forget that I'd done that.
Either way, problem solved, and a general cheer from an enthusiastic RMMV member. Have a round of applause...

'Best of Breed' Star awarded, and my thanks. I'll add you to the Credits of Rachdale Cheese and update the Web version this evening. Many thanks.
[doublepost=1468632585,1468626607][/doublepost]Follow-up (for the moment...)...

I tried again calling a Common Event straight from the NPC Event, but couldn't get it to work. I could get the Timer or Wait commands to run, but this would always 'freeze' both the NPC and the Party until time was up. Whatever I tried that kept the Party moving would not trigger the Self-Switch Off, so the NPC (the boar...) would continue to career around indefinitely.
I'll go for the array version until struck by inspiration at a later date; it's working fine; thanks again. The boar now bites, then chases for ten seconds. If the Hero is bitten again, the ten seconds is re-set. Good luck to those strolling through these woods, I say..! On to the next Map. Now then, what surprises can I come up with for the Lost Forest..? Hmm...
 
Top