Timed Transformations

So this is my first time posting a topic so if this is the wrong location then I apologize in advance.

Basically I have two over world sprites, one is the player normally seen and the second one is them inside of a box (For a kind of stealth mode). I already figured out the coding for the player to open the item menu, select the box item and then have it swap the player sprite for the box alternative. The problem I'm facing is having the item last for 10 seconds and then automatically change back to player mode which is the part I am having difficulty figuring out. I got an image of the code attached down below. The last if timer part was my last attempt at solving it before resorting to posting my issue here. I appreciate any help I can get.

Orange Box.png
I've moved this thread to RPGMaker MV. Please be sure to post your threads in the correct forum next time. Thank you.
The problem is that this common event is only called once (when you use the item). It then sets the timer to 10 seconds and checks immediately after that whether the timer has run out (which it can't have, since it was just set to 10 seconds before).


Instead of the second if-branch turn on a switch ("Box Timer running" or something like that)


Move the if-branch that checks for the timer to a new common event. Set that event to Parallel and have the "Box Timer" switch as condition. Inside the common event, the commands should look like this (pseudocode):


If Timer <= 0 min 0 sec


    Change Actor Graphic


    Control Switches: Box Timer running = OFF


End


Wait 30-60 Frames (to prevent lag)


This way, after you started the timer it will check once or twice a second if the timer has run out. If it has, it changes the actor graphic and turns off the switch so that it doesn't keep checking for the timer.


Hope that helps  🙂
What LadyBaskerville said, or you could set up a "jump to label" as an else on your timer. so for example:


Label: Check


If Timer <= 0 min 0 sec


    Change Actor Graphic


Else


Jump to Label: Check


End


That will keep the event looping until the timer reaches 0 and will then run as you want it to. it may cause some lag, so you could add in a "wait" line, just be sure to set it to a parallel process otherwise your game will freeze until the timer runs out. I would personally leave that out though! 

Original thread: https://forums.rpgmakerweb.com/threads/timed-transformations.70511/