I just found something really nasty. A variable declared globally, that is, in a C file but outside any function, that has an initialization, does not get set to the initialization value except the very first time it is ever run. A saved game might load a different value and the initialization is not performed.
For example, I had the following code:
bool Surrendered = false;
But Surrendered was true after boarding was done and I saved the game. Next time I loaded the game, the variable was not initialized to false, as you would expect from C code, but loaded as true from the saved game. If you have variables that need to be initialized to a specific value when a module is run, you need to set them explicitly in one of your functions. It might be best to treat all global variables as uninitialized.
A global variable declared in a module loaded with LoadSegment may be initialized properly. But modules that are always loaded do not get reinitialized.
I hope this makes sense. It may be the source of a lot of bugs.
Hook
For example, I had the following code:
bool Surrendered = false;
But Surrendered was true after boarding was done and I saved the game. Next time I loaded the game, the variable was not initialized to false, as you would expect from C code, but loaded as true from the saved game. If you have variables that need to be initialized to a specific value when a module is run, you need to set them explicitly in one of your functions. It might be best to treat all global variables as uninitialized.
A global variable declared in a module loaded with LoadSegment may be initialized properly. But modules that are always loaded do not get reinitialized.
I hope this makes sense. It may be the source of a lot of bugs.
Hook