If I do that it still doesn't work - and that shouldn't make any difference because the THEN command should work. However I have found that if I omit these lines with the comment double slashes it works.
If I change the gPlayerBasePosition to a constant like 90 it still crashes.
It's just so random, it seems like memory overruns to me.
function updateItems
// go through all scene objects created
for i = 0 to gTotalItems
// if there is a valid sprite attached draw it
if gScene[i].sprite <> 0
// draw it
SetSpritePosition( gScene[i].sprite, gScene[i].x + (cameraX# * gScene[i].px), gScene[i].y + (cameraY# * gScene[i].py))
// is it an enemy?
if gScene[i].name = "Enemy"
processEnemy( i )
endif
endif
// check for upkeep
processUpKeep( i ) // THE ERROR MAKES i GO TO 497 ALL OF A SUDDEN AFTER CALLING PROCESS ENEMY - for no reason - BUG!!!!!!
next
endfunction
function processEnemy( i )
//
// move the current object
//
// !!!!!!!!!!!!!! OMITTING THESE LINES STOPS IT CRASHING
//if gScene[ i ].x > gPlayerBasePosition
gScene[ i ].x = gScene[ i ].x - gScene[ i ].speed
//endif
endfunction
EDIT: I managed to fix this by moving the processUpKeep() call to be above the processEnemy() call like this... what ever happens in process processEnemy causes i to go out of range.
// go through all scene objects created
for itemX = 0 to gTotalItems
// check for upkeep - !!!! MOVE UP HERE TO AVOID CRASH
processUpKeep( itemX )
// if there is a valid sprite attached draw it
if gScene[itemX].sprite <> 0
// draw it
SetSpritePosition( gScene[itemX].sprite, gScene[itemX].x + (cameraX# * gScene[itemX].px), gScene[itemX].y + (cameraY# * gScene[itemX].py))
// is it an enemy?
if gScene[itemX].name = "SoldierLevel1_enemy"
processEnemy( itemX )
endif
endif
/// !!!!! MOVED FROM DOWN HERE
next itemX