PDA

View Full Version : Multidimensional arrays for game - - explain me plz.


RealBBoy
07-25-2001, 02:52 PM
Hi,

I would like to know if someone can explain 2 me or point me in the right direction, regarding multidimensional arrays.
We are currently doing a research for a strategy game.
Table in the game is 10x10 squares (each square 10x10px). Informations about the each square (owner, population, army, defence) are stored in md array, right?

Example:

field E 4,2 is Mike's land populated with 400 peps and has army of 240 niggaz and their def factor is 8.

so basicaly if a player put more troops there i need to make calculations and write them back to array, or something like that.

..hope that you understand me...or i am dazzing of again..:()

20 Ton Squirrel
07-25-2001, 05:42 PM
Arrays are like tables, as you already have discerned. Actionscripting handles arrays SO much better than VB, which I'm usually stuck using (feh). That being said, gaze below at this array:

gomph = ["narf", "snoogans", "chump"];

This is a single-element array. To return a value from the array you would simply reference the position you want, starting with an index of 0. Like this....

gomph[1] -==> "snoogans"

Pretty basic, ja? Now check this action out...

scoomag = [["narf", "miggle", "saskatchiwan"], ["humidor", "muckluck", "snootchy"]];

This is a multi-dimensional array. Basically, it's an array that contains an array. You can nest any number of arrays, it all depends on what you want out of it. With the above example, you'd reference it like this:

scoomag[0] -==> ["narf", "miggle", "saskatchiwan"]
scoomag[1][2] -==> "saskatchiwan"

See? If you wanted to change a value in that array, you'd do something like dis:

scoomag[1][2] = "gnafawil";


There are a myriad of functions fer the array. Things like splice and push are my favorite. They allow you to kill out elements in the array or add them in. Check out the help documentation for the array functions. You'll get a good idea on how to manipulate the data from there.

Good luck, don't let no one bust a cap in yo' arse.

RealBBoy
07-25-2001, 05:48 PM
So, basicaly:
after that i use functions to calculate new data to store in arrays, using variables.

If after this i am right..then i am geting somewhere...