Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: Snarky on Sun 01/03/2015 14:35:21

Title: repeatedly_execute_always() functions in script modules - order of execution
Post by: Snarky on Sun 01/03/2015 14:35:21
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.
Title: Re: repeatedly_execute_always() functions in script modules - order of execution
Post by: monkey0506 on Sun 01/03/2015 17:19:47
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.
Title: Re: repeatedly_execute_always() functions in script modules - order of execution
Post by: Monsieur OUXX on Tue 03/03/2015 10:36:26
+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 ;)
Title: Re: repeatedly_execute_always() functions in script modules - order of execution
Post by: Snarky on Tue 03/03/2015 11:57:39
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.
Title: Re: repeatedly_execute_always() functions in script modules - order of execution
Post by: Radiant on Thu 05/03/2015 12:48:31
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.
Title: Re: repeatedly_execute_always() functions in script modules - order of execution
Post by: Snarky on Thu 05/03/2015 13:13:29
Yes, that's what I ended up doing (for all the related scripts).