Letting the event wait until a function is done?

Hey guys,

When i make a function and call it from a common event or regular event, the event immediately moves on to the next line before the function is actually done with whatever its doing, how can I prevent this? The only solution ive gotten so far is putting a this.wait() inside the function - but since i dont know how to find out how long a function actually takes before its done; that doesnt seem like the best option.

Any solutions, advice or tips on how to deal with this issue?

Thanks in advance!
You just found out why it's usually easier to let the control for background tasks be handled by the engine's parallel processes...

It is possible to do what you want, but it will require you to implement it in one of two ways - either have your script function implement itself as an element in the game loop and add the properties there for it to have its own wait sequence (this is needed if other updates on the engine should work regularly), or make your own wait loop inside the common event (only possible if you can allow other parts to be stopped while your function works).

the second option would be a loop around two commands in your common event: a wait(2) and a conditional branch for breaking the loop once a switch is ON.
Then you have to have your function switch that ON after it is completed.
@Andar Your solution seems to work, thanks alot!

Original thread: https://forums.rpgmakerweb.com/threads/letting-the-event-wait-until-a-function-is-done.96357/