Question about update.c script

Bloodbane

Well-known member
Recently I've been playing with update.c and file reading & writing scripts to create unlock/lock system. The system works great :)
But it turns out there are couple things I need to know about update.c so here are the questions:

1. When exactly update.c started to be run if alwaysupdate isn't set?
2. Same as #1 but with alwaysupdate set to 1
 
Found it in openbor.c

alwaysupdate in the code is defined in the code as

execute update/updated scripts whenever it has a chance

The command on the other hand is defined as

execute update script whenever update() is called

The points where this variable is called over is in update() part of the code.

Here's the order (bold are parts where the the variable is affected. Normal is in parenthesis):

update.c (if not paused and is in game)
keyscripts
slowmotion
update level time
update status
update entities
graphics queue
sprite queue
entity queue
updated.c (if is in game)
pause menu code
sound
 
Therefore, if alwaysupdate is on, update.c and updated.c will just keep on going regardless if it's paused and or not in game.

It's wise therefore to use the respective openborvariants that flag if the game is, say in the level or in the select screen perhaps, to control the way the code is flowing.

ADDENDUM: I'm not that sure if that's how it was, but that's how I saw the code anyway.
 
Hmmm... so am I right to think that update.c will be run even during loading and intro scenes, if alwaysupdate is set to 1?

Anyways, my real purpose of asking this is to find best time to read from file. I've used loading.c to do that before and for some reason, it caused some bugs. Since there are no other script run during main menu, update.c is the only script to the file reading scripts. Currently, I use oncreate function inside update.c to ensure file reading scripts are only run once

Also I'd like to know when ondestroy (also used by update.c) is run. I had impression that if update.c is not run during main menu (alwaysupdate isn't set to 1 that is), ondestroy function might be run more than once (?)
Or both oncreate and ondestroy will only be run once regardless of alwaysupdate setting?
 
Bloodbane said:
Hmmm... so am I right to think that update.c will be run even during loading and intro scenes, if alwaysupdate is set to 1?

Yeah, I think. Normally update.c would run if the level is currently not paused and updated.c would just run in a level regardless if it's paused. I guess that's why updated is mostly the one used for effects regarding the menu and such.

Bloodbane said:
Currently, I use oncreate function inside update.c to ensure file reading scripts are only run once

You used what a similar technique used in RocketViper 2.4 where the resources are loaded upon the start of the menu? (I do think it's not, but I'm just checking)

Lastly ...

Bloodbane said:
Also I'd like to know when ondestroy (also used by update.c) is run.

From what I saw in the code, it's run by the script interpreter and not the main openbor update itself, so yeah, I think regardless of alwaysupdate, it would still run since regardless, it would be read by the interpreter anyway.

These statements need confirmation though, since that's how I read it anyway.

EDIT, sorry about the edit. I did not clearly read the last question.
 
Back
Top Bottom