Event speed resets after being activated by switch and refuses to change afterwards

So i change my even movement with command

$gameMap.event(1).setMoveSpeed(0.01855)

It works well, but if i activate that event with switch afterwards, the speed will reset.
What is weird, is that if i try to apply that command AFTER activating the switch for the event, it will ignore it. I don't understand why, and hope that someone else knows the answer.
best way is store that speed into a variable or elsewhere.
if the speed is re-used for others, call it once per map transfer or when inside
that map to restore it.
best way is store that speed into a variable or elsewhere.
if the speed is re-used for others, call it once per map transfer or when inside
that map to restore it.
I have no idea how to do that. I can make a variable with certain number, but how do i set speed from the variable to game event? I can't even imagine what kind of command would do that.
And no, i don't need it for other maps, just for certain event within one map.
It works well, but if i activate that event with switch afterwards, the speed will reset.
Each page has its own speed you can set for the event (next to move route) - whenever the page changes, event's speed will be set to the new page's speed.
Let's go back to the first issue.

If something goes wrong after a switch is used, then it is almost guaranteed that said switch has a forgotten or never configured second use.

most commonly switches activate common events, and a parallel common event that constantly sets the speed would explain that behaviour.

or the second most commonly missed use is if a plugin is configured to use that switch by default for something, and you forgot to configure that plugin correctly (plugin configuration includes checking if a plugin uses switches and variables and if yes, reserve them so nothing else uses them)
To expand on what Mac said...
if i try to apply that command AFTER activating the switch for the event, it will ignore it. I don't understand why, and hope that someone else knows the answer.
Each frame, the map refreshes itself if needed (which also refreshes all events), then updates all its events one after another. Changing page is part of an event's refresh.

When a potential event page condition is toggled, e.g. a switch, the map is told to queue a refresh (cf .refreshIfNeeded(), rpg_objects.js). That might happen earlier than the start of next frame, depending on the exact sequence of commands: by default the only "early refreshes" happen when a triggered event starts, or when the Set Movement Route command runs.

For your example:
  • Event A - the one that is turning on the switch.
  • Event B - the one with a page condition based on that switch.
If event A is just "Control Switches, Script", there's no early refresh in A. That means event B will be refreshed after this frame's update of event A - either at the start of next frame, or by an early refresh from another event.

Long story short: try adding a Wait 1 frame immediately before your Script command.
Thanks, it's worked! Weird, i kinda thought about not instant refresh so i put change player speed command first, then change event speed. The idea was for it to process something else before event speed. But it didn't work. And the wait 1 frame worked. So i guess executting a command takes even less than 1 frame.
So i guess executting a command takes even less than 1 frame.
yes and no - it depends on the command and what it does.

the engine tries to execute as many commands as possible in a single frame, but some commands require time to be displayed on the screen.

if you're only using commands that have no direct effect, then the frame update only happens after all of them.
This is also the reason why a wait reduces lag in case of parallel processes - it stops the processing of the event to allow other events to be processed for cases where the result is not needed every frame

Original thread: https://forums.rpgmakerweb.com/threads/event-speed-resets-after-being-activated-by-switch-and-refuses-to-change-afterwards.177379/