• New Horizons on Maelstrom
    Maelstrom New Horizons


    Visit our website www.piratehorizons.com to quickly find download links for the newest versions of our New Horizons mods Beyond New Horizons and Maelstrom New Horizons!

Important notice to all coders

LarryHookins

Buccaneer
Staff member
Storm Modder
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
 
Wow. That sounds worrisome! <img src="style_emoticons/<#EMO_DIR#>/piratesing.gif" style="vertical-align:middle" emoid=":shock" border="0" alt="piratesing.gif" />

I must check my own code for stuff like that. <img src="style_emoticons/<#EMO_DIR#>/piratesing.gif" style="vertical-align:middle" emoid=":shock" border="0" alt="piratesing.gif" />
 
Back
Top