Execution of script on game load
In the dmod I'm working on there are various ticking-counters which need to be running continually.
The method I'm using currently is to spawn(); them in the start-1.c. This then presents the problem of them unloading when the player resumes the game. My solution to this is to then have a launch script attached to screens with savebots on them. This script when loaded will execute a "term" procedure in the ticking scripts with an external(); and then spawn(); them again.
While this method is working, it is somewhat heavy handed and limits what I can do on savescreens.
Also the ticking counter's values are stored in globals.
Edit: Is there a way to check if a script is currently loaded into memory/executing? I had a dig in the dinkc reference and couldn't find anything.
Edit 2:OCD Formatting and grammar
So my question to you is there an easier solution to this?
The method I'm using currently is to spawn(); them in the start-1.c. This then presents the problem of them unloading when the player resumes the game. My solution to this is to then have a launch script attached to screens with savebots on them. This script when loaded will execute a "term" procedure in the ticking scripts with an external(); and then spawn(); them again.
void term (void) { kill_this_task; debug("Tick Killed"); }
While this method is working, it is somewhat heavy handed and limits what I can do on savescreens.
Also the ticking counter's values are stored in globals.
Edit: Is there a way to check if a script is currently loaded into memory/executing? I had a dig in the dinkc reference and couldn't find anything.
Edit 2:OCD Formatting and grammar
So my question to you is there an easier solution to this?
Hello
Does using external actually affect the spawned script? I would've thought it creates a new instance of it, odd.
"Is there a way to check if a script is currently loaded into memory/executing?"
Not as such, but you can save the script number to control it later. For example:
What might be helpful to you is a way to know if a game is being loaded or not - that way you can spawn the timer if it's a loaded game and do nothing if the player has just walked onto the screen.
To do this, make a global &loadedgame or something. In the savebot script set it to 1 just before saving and set it back to 0 straight afterwards. Then in the main() of the savebot you can do:

Does using external actually affect the spawned script? I would've thought it creates a new instance of it, odd.
"Is there a way to check if a script is currently loaded into memory/executing?"
Not as such, but you can save the script number to control it later. For example:
&global_var = spawn("timer"); //later run_script_by_number(&global_var, "term");
What might be helpful to you is a way to know if a game is being loaded or not - that way you can spawn the timer if it's a loaded game and do nothing if the player has just walked onto the screen.
To do this, make a global &loadedgame or something. In the savebot script set it to 1 just before saving and set it back to 0 straight afterwards. Then in the main() of the savebot you can do:
if (&loadedgame) { //It's a loaded game! Do stuff spawn("timer") }
Yup calling term using external will kill the script you called from, not the script you want to kill. You need to call it like Sparrowhawk suggested here.
From memory we had a discussion on spawning scripts after a save recently, and Paul (I think it was) found he could just spawn things from main.c which would seem to be perfect for you
From memory we had a discussion on spawning scripts after a save recently, and Paul (I think it was) found he could just spawn things from main.c which would seem to be perfect for you
Oh wow. I can't believe I hadn't thought of that.
Thank you!
Thank you!
Have you checked out this thread? It starts out a little confusing, but by the end we had a pretty solid way to launch these kind of scripts worked out.
The gist of it is that main.c runs every time you load a game. It also runs on the title screen, but it should be easy enough to check which is which using if (&story > 0) or something like that. Like any other script, main.c gets killed when a screen draws (including the initial screen on loading a save), so to prevent that you have it either script_attach(1000) or just have main.c spawn() a new script, which will keep running after main.c stops.
The gist of it is that main.c runs every time you load a game. It also runs on the title screen, but it should be easy enough to check which is which using if (&story > 0) or something like that. Like any other script, main.c gets killed when a screen draws (including the initial screen on loading a save), so to prevent that you have it either script_attach(1000) or just have main.c spawn() a new script, which will keep running after main.c stops.
Me too! How on earth did it take us 15 years to figure that out?