Many weeks ago, I have had this particular bug reported by a beta tester and didn't make a huge effort to track it down at the time.
I have since had the same inexplicable error where a global variable obtains an unexpected value.
When I experienced it myself, I have been very thorough in locking it down.
The following global variables are declared in the main unit:
global LandersInWorld as Integer
global BaitersInWorld as Integer
global BombersInWorld as Integer
global PodsInWorld as Integer
global SwarmersInWorld as Integer
global HumanoidsInWorld as Integer
global MutantsInWorld as Integer
The ONLY place where e.g. "HumanoidsInWorld" is incremented is in the createHumanoid() function.
I wrote out to a log file when code in the function was executed (logged from within the function).
Next, I had to play around in the game for about 10 minutes killing humanoids until the amount left was 0 and restarting, trying again.
Eventually, at an arbitrary amount left (maybe 2) the variable now contains 6! Checking my log file, there is only the expected evidence that the initial 10 were created as expected.
There is no other code where these variables are incremented.
Now, I put this down to a compile error initially (I have seen this before where certain datatypes aren't on certain memory boundaries etc, but it can happen intermittently here on the same compile).
There is a complex structure preceding these global variables:
global dim PortGFX[1] as Integer
global LaserMaster as tLaser
global dim Laser[10] as tLaser
global dim ThrustNozzle[4] as Integer
global dim ThrusterSpriteID[2] as Integer
Global dim Parallax1[8] as tParallax
global dim mapplot[7] as Integer
global dim GlobalHeightMap[8192] as Float
global dim HumanHeightMap[8192] as Float
// new landscape
global Dim LandScapeCells[512] as tLandscapeCells
global Dim HazePatching[7] as Integer
global dim FragmentExplodeOffsets1[64] as tFragmentExplodeData
global dim FragmentExplodeOffsets2[64] as tFragmentExplodeData
global dim FragmentExplodeOffsets3[64] as tFragmentExplodeData
global dim FragmentExplodeOffsets4[64] as tFragmentExplodeData
global dim FragmentExplodeOffsets5[64] as tFragmentExplodeData
global dim FragmentExplodeOffsets6[64] as tFragmentExplodeData
global dim FragmentTeleport[64] as tFragmentExplodeData
global dim FragmentExplodeOffsetsPlayer[512] as tPlayerExplodeData
global dim FragParticleQueue[64*20] as tNewFragmentArray
global dim FragEvents[20] as tFragEvent
global dim OriginalFragCells[64*6] as Integer
(and quite a lot more dimensional declarations above that).
I don't see this corruption anywhere else apart from this bunch of variables.
I've checked that I'm not overflowing my arrays (and anyway, won't that raise an exception anyway?)
This has been happening for months, but I've never dug into it until now. I don't write repeatedly into the preceding variables (only at load time). Anyway, I doubt if the variables are stored in the same order in memory as they are in my code.
I'll do some more testing, examine the frequency as well as try the same debug on the surrounding variables.
I'm on 1.08.14 now, but this was happening back at 1.07.6 as well.