JLowther

Veteran
Veteran
Joined
Feb 20, 2016
Messages
327
Reaction score
40
First Language
English
Primarily Uses
I need to verify that my observations aren't leading me astray and that I am, in fact, seeing things for how they're actually happening. Someone please sanity check me on the following...

If multiple map events attempt to run the same common event simultaneously, the lowest numbered event will begin running it first, correct?

I'm using common events for handling various tasks (like requesting a random number between specific variable values) and I just want to be sure I know how the order of events will happen.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,789
Reaction score
15,916
First Language
English
Primarily Uses
RMMV
When events run, they do so in event id order. However, whether they will call the common event in the same order depends on what happens within the events themselves - anything that does any kind of pause will allow a higher-numbered event to jump in ahead while the event is pausing (for example, the Wait command, or a move route, will allow other events to continue running while this one is in the wait stage).

I would not rely on them running the common event in the same order.
 

JLowther

Veteran
Veteran
Joined
Feb 20, 2016
Messages
327
Reaction score
40
First Language
English
Primarily Uses
When events run, they do so in event id order. However, whether they will call the common event in the same order depends on what happens within the events themselves - anything that does any kind of pause will allow a higher-numbered event to jump in ahead while the event is pausing (for example, the Wait command, or a move route, will allow other events to continue running while this one is in the wait stage).

I would not rely on them running the common event in the same order.

Perfect. This is consistent with my findings.

And yeah, I figured out that even one frame of difference would give an event with a higher ID a head start so I'm giving all of these common events a conditional that checks to see if the first variable the event will modify is currently at 0.

If not, that becomes the "occupied" sign that informs any other events that these variables are in use and to check back every 5 frames until the current event "exits" the common event by setting that variable to 0 as it completes.

Thanks again, Shaz. You're a champ, as always.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,789
Reaction score
15,916
First Language
English
Primarily Uses
RMMV
Having multiple events call the same common event that uses or updates a variable, and then the events doing something to that variable, is always a risky thing. If they happen to be running at the same time, you could have one that sets the variable to something, then before it gets a chance to check what it is, another will change it.

One thing you could do is to get yourself a "self variables" plugin, and use the self variables in the event and common event. That way, regardless of the order in which they run, the common event called from one event will always only modify that event's self variables, and nobody else's. Yanfly has one that looks nice and easy, and doesn't require his core engine.

It depends on what you're trying to do though.
 

JLowther

Veteran
Veteran
Joined
Feb 20, 2016
Messages
327
Reaction score
40
First Language
English
Primarily Uses
Having multiple events call the same common event that uses or updates a variable, and then the events doing something to that variable, is always a risky thing. If they happen to be running at the same time, you could have one that sets the variable to something, then before it gets a chance to check what it is, another will change it.

One thing you could do is to get yourself a "self variables" plugin, and use the self variables in the event and common event. That way, regardless of the order in which they run, the common event called from one event will always only modify that event's self variables, and nobody else's. Yanfly has one that looks nice and easy, and doesn't require his core engine.

It depends on what you're trying to do though.

I'm not worried about the events doing their thing because it's always going to be a one-off action that happens momentarily (such as an event using the logic in a common event to determine where to spawn relative to the player) so there shouldn't be an issue with this "queue" existing (and these actions won't happen that frequently anyway).

That said, self-variables are something I should absolutely look into because they'll negate the need for a lot of the gatekeeping I've been adding here...

Thanks! :)

EDIT: Yeah, this will help a great deal but before I can even really use it, I need to do a bit of paradigm shifting in my head because of how much this can change for me.

Immediately, I think about one particular case where I have players prying open a vent cover with a screwdriver by mashing a button and how I had wanted to save the number of mashes they had put in before walking away (as they have the option to run if something is chasing them and they're not going to succeed on prying it open in time) but that would mean having a different variable for EACH event and "no thanks" to that.

Again, thanks so much and I have a lot of mulling to do, heh...
 
Last edited:

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
36,682
Reaction score
9,859
First Language
German
Primarily Uses
RMMV
As additional info, you might want to read through the "bughunting" tutorial in my signature.
It contains some background info on timing problems that might be helpfull as well.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,789
Reaction score
15,916
First Language
English
Primarily Uses
RMMV
Immediately, I think about one particular case where I have players prying open a vent cover with a screwdriver by mashing a button and how I had wanted to save the number of mashes they had put in before walking away (as they have the option to run if something is chasing them and they're not going to succeed on prying it open in time) but that would mean having a different variable for EACH event and "no thanks" to that.

What "each event"? If you have one vent cover, that's one event. What other events do you need to use variables on?

And, btw, "a different variable for each event" is exactly why "self variables" exist. You can put the same code on each event (even set one up and copy/paste to the others), and when they update the variable, it's their version of the variable that's being updated. Just like self switches - if event 1 turns on self switch A and event 2 checks self switch A, it's looking at its own self switch A, not the same one that event 1 is using. Self variables do exactly the same thing. Event 1 could use self variable 1, and event 2 could use self variable 1, but they are different variables, and they can only see/modify their own (unless you use a script/plugin call to make an event deliberately look at someone else's self variable).
 

JLowther

Veteran
Veteran
Joined
Feb 20, 2016
Messages
327
Reaction score
40
First Language
English
Primarily Uses
What "each event"? If you have one vent cover, that's one event. What other events do you need to use variables on?

Multiple vents per level, in this case.

And, btw, "a different variable for each event" is exactly why "self variables" exist. You can put the same code on each event (even set one up and copy/paste to the others), and when they update the variable, it's their version of the variable that's being updated. Just like self switches - if event 1 turns on self switch A and event 2 checks self switch A, it's looking at its own self switch A, not the same one that event 1 is using. Self variables do exactly the same thing. Event 1 could use self variable 1, and event 2 could use self variable 1, but they are different variables, and they can only see/modify their own (unless you use a script/plugin call to make an event deliberately look at someone else's self variable).

I know, which is why I have to rethink a great deal of the previous designs I was working with.

Each vent CAN have its own unique button mash counter without needing to assign it its own variable. I'm likely going to wind up having fewer global variables than self variables when all is said and done.

As additional info, you might want to read through the "bughunting" tutorial in my signature.
It contains some background info on timing problems that might be helpfull as well.

I will do that, thanks!
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,789
Reaction score
15,916
First Language
English
Primarily Uses
RMMV
I'm likely going to wind up having fewer global variables than self variables when all is said and done.

The joy of self variables is that you only have to define them once, and then all events will have that self variable.
 

JLowther

Veteran
Veteran
Joined
Feb 20, 2016
Messages
327
Reaction score
40
First Language
English
Primarily Uses
The joy of self variables is that you only have to define them once, and then all events will have that self variable.

Absolutely.

And I was saddened when I realized that commands like:

$gameVariables.setValue(73,$dataMap.events[$gameVariables.value(79)].x);

...Weren't working with Yanfly's plugin, but then massively relieved when I remembered that the "Control Variables" command has a script option where I can place "$dataMap.events[$gameVariables.value(79)].x" and it works like a charm for self variables as well.

This made this project leaps and bounds easier. Thanks yet again, Shaz. I've used Yanfly's plugins extensively yet somehow never bothered to look at this one for some reason and you best believe I'm kicking myself for it...
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
44,789
Reaction score
15,916
First Language
English
Primarily Uses
RMMV
I was very happy when I found that plugin. I had started to write my own so it saved me a lot of work! I deliberately try to avoid using other people's plugins for a number of reasons, but this one will be an exception to that rule :)


You realise this
Code:
$gameVariables.setValue(73,$dataMap.events[$gameVariables.value(79)].x);

will give you the event's x position as you placed it in the editor, right? It won't give you the event's current position on the map if it has moved from its original location. You would need to use this code instead, if you wanted the current position of a moving event:
Code:
$gameVariables.setValue(73,$gameMap.event(79).x);
 

JLowther

Veteran
Veteran
Joined
Feb 20, 2016
Messages
327
Reaction score
40
First Language
English
Primarily Uses
You realise this
Code:
$gameVariables.setValue(73,$dataMap.events[$gameVariables.value(79)].x);

will give you the event's x position as you placed it in the editor, right? It won't give you the event's current position on the map if it has moved from its original location. You would need to use this code instead, if you wanted the current position of a moving event:
Code:
$gameVariables.setValue(73,$gameMap.event(79).x);

I did not, but I will definitely use this in the future! :D

That saved me from asking a question down the road for sure...
 

Latest Threads

Latest Posts

Latest Profile Posts

Only 3 more days to get your copy of Move That Box! with -15% discount!
1660090657213.png
Mistakes will be made.
After three years, it was awesome to be back at Gen Con!
Words of Wisdom: You can be honest and alone. Or dishonest and together.
Working on mapping using RPGTools to create parallax maps using PVgames tiles/assets. It's super cool... but mapping is still something I drag my feet on getting done. I hate this but love the math parts of design, which is the opposite of a lot of dev's around, I think. It really do be different strokes for different folks.

Forum statistics

Threads
124,381
Messages
1,163,229
Members
163,180
Latest member
Viking
Top