Game Development Community

What context(s) do scripts run in?

by Keith G Wood · in Technical Issues · 05/01/2011 (7:32 pm) · 1 replies

Basically I need to know if all my scripts run in a single context, or whether there are multiple contexts (& hence a danger that one piece of script might get interrupted part way through by another piece of script).

I'm assuming all script IS executed in the same context - I just want to check.

My specific issue is I have a (model) resource that can be created and deleted depending upon various actions in the game.

I also have script that checks a stored model handle (set to zero when the model is deleted) to determine whether the model currently exists, and then (if it does) carries out specific actions to that model.

What I don't want to have happen is I test the model exists, and then (before I get round to performing actions on the model) some other piece of script interrupts & deletes the model.

Now, if all script is executed in the same context, then this cant happen. But if (say) there were different contexts for scripts that are scheduled and scripts executed on events (such as key presses), then there is a chance for a very small window of opportunity for this to happen.

My code is working fine - I just want to be sure it always will (i.e. that there are no such windows of opportunity).

#1
06/15/2011 (6:11 pm)
All in the same context.

I came across an issue with animation where moving a sprite across the screen prevented all other scripts from running. I broke down the animation into a function that animates a step, then calls itself in 50ms for the next step. That's the only way I can let other scripts run, hence, a single context.