PDA

View Full Version : I need some help with Arrays.



woad
June 17th, 2006, 07:54 PM
So, i'm making a military command type game and I'm using arrays to hold what's in the armies of the game. So let's say there's a unit array of all the different units in my army. Units = ["Pikemen", "Swordsmen"] . How would I give properties to one of them? Say I need to change the amount of swordsmen I have after a battle and also give them more experience.
Would it be something like units[1].exp += 50 ?

Or maybe, should I not be using arrays at all?

INSANE SYTH
June 17th, 2006, 09:10 PM
Yes you should be using arrays, you will just want to use a 2 dimensional array as aposed to a single dimensional array:

Armies:Array = new Array();
Armies.push({type:"pikemen", number:"50"});
Armies.push({type:"swordsman", number:"100"});

you would call it thus:

myVariable1 = Armies[0].number;

this would return 50.

Hope this helped.

woad
June 17th, 2006, 10:52 PM
Thx Insane, that just made anything a whole lot easier.

INSANE SYTH
June 19th, 2006, 07:09 AM
anytime.