I feel the exact same way sometimes. It's okay to overcomplicate things (as long as you mean it in a good way). If nothing slows the game down then don't worry. You can always go back and change things if they don't work.
var CombatantsList = []CombatantsList.push( MapEntityList[1] )
CombatantsList.splice( 0, 1 )
MapEntityList[1].update()
The MapEntity and MapEntityList arrays are unaffected when you splice from CombatantsList. You'll need to touch them as well if you actually intend for them to be removed when spliced from CombatantsList.
function NewUpdateScript() { for ( i in MapEntityList ) { MapEntityList[i].update() } if ( Combat == true ) { Combat.process() } for ( i in MapEntityList ) { if ( MapEntityList[i].erase == true ) { DestroyPerson(MapEntityList[i].personsname) MapEntityList.splice(i, 1) } }}
for ( var i = 0; i >= MapEntityList.length; ++i ) { //if, DestroyPerson and .splice here}
function NewUpdateScript() { for ( i in MapEntityList ) { MapEntityList[i].update() } if ( Combat == true ) { Combat.process() } var cleaning = false var cleanindex = 0 var mapclean = false while ( mapclean == false ) { for ( i in MapEntityList ) { if ( MapEntityList[i].erase == true ) { cleaning = true cleanindex = i break } } if ( cleaning == true ) { DestroyPerson(MapEntityList[cleanindex].p) MapEntityList.splice(cleanindex, 1) cleaning = false } else { mapclean = true }}
function NewUpdateScript() { for (var i = 0; i < MapEntityList.length; i++) { MapEntityList[i].update(); if (MapEntityList[i].erase) { DestroyPerson(MapEntityList[i].personsname); MapEntityList.splice(i, 1); i--; // this is the key! } } if ( Combat ) Combat.process();}
function CreateGlobalData() { return { map_array: [], people_array: [], //... etc. };}var Data = CreateGlobalData();Abort(Data.map_array);
It's a very good idea to put as many colors as you can into a global object and use CreateColor at startup. Same with images and surfaces, sounds, etc.... You can go even further, too. Make global objects that hold key constants and such, which will help with changing keys for actions and such (especially compared to hardcoding).
In larger Sphere games I've commonly seen data structures such as Global, Engine, Data, or Game. And then you just tack on all the stuff you want to persist.
While we are talking about global objects and all that...It's a very good idea to put as many colors as you can into a global object and use CreateColor at startup. Same with images and surfaces, sounds, etc. (although it's more tempting, for me anyway, to put CreateColor calls inline than the others). Your game will run smoother, give the garbage collector an easier time, and use less memory.
lifebar = new LifeBar(boss.maxHP, ColorCache.Green);// then later on:// manipulates properties of lifebar.color, which is set to your cached Green color object by the constructor!lifebar.tweenToColor(ColorCache.Red);// ...and then somewhere else:Rectangle(0, 0, 100, 100, ColorCache.Green);