repeatedly_execute_always() functions in script modules - order of execution

Started by Snarky, Sun 01/03/2015 14:35:21

Previous topic - Next topic

Snarky

Just a general question about using multiple script modules. If you have several scripts that have repeatedly_execute() or repeatedly_execute_always() handlers, is there any guarantee about the order they will be executed in? (E.g. the order of the script files in the editor.) I have some complicated logic around predicting what will happen the next game cycle that I'm trying to debug, and it relies on different repeatedly_execute_always() functions always being in sync in the expected order.

monkey0506

AFAIK the game loop cycle always runs the rep_ex_always of each module, in the order they are listed in the editor, with GlobalScript and then the current room's script being the last to run. After every script's rep_ex_always runs, I believe that every script's rep_ex is run, then other events. It would be pretty simple to add Display statements to verify the order, but I'm reasonably certain that rep_ex_always runs in the order you'd expect.

Monsieur OUXX

+1

From experience, I'm almost certain that they run in same the order as the scripts' order as seen in the Editor. If that was not case and if that caused a bug in my scripts "dependencies", then I never spotted it ;)
 

Snarky

Thanks. I thought so, but I was having some weird bugs in code that crossed multiple scripts, and if it didn't work as I assumed that would explain it.

I think in the end the problem was in my head. I built these weird structures that would always run certain update functions when you tested a value *unless* it had already been updated this cycle, and in the process somehow convinced myself that the remaining bits of repexec would run *after* the repexec of a lower script. But of course that would never happen by itself. I ended up refactoring out all the "game cycle" logic into separate functions, and called them all in my desired order from the repexec in the bottom script. Still didn't work properly, but at least it made sense.

Radiant

The straightforward workaround is to have only one rep_ex function, and have this call functions from different modules (e.g. screenmodule_update, joymodule_poll, etc) as needed.

Snarky

Yes, that's what I ended up doing (for all the related scripts).

SMF spam blocked by CleanTalk