Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
Rennekon
20
Years of Service
User Offline
Joined: 7th Oct 2003
Location:
Posted: 5th Sep 2004 03:14
So what exactly is the point of an "Array." I've heard they're used to store large amounts of data and acces them easily. BUt, I have no idea how to use them or the exact advantages of them. Any explanations?

John "Dark Lord of Angel Destroying Destiny" Pringlebee, maybe?
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 5th Sep 2004 04:43 Edited at: 5th Sep 2004 04:49
suppose you wanted to change a list of numbers at frequent intervals, for example the armour left to battle units one to fifty, you could write your game code like this

impact=object hit (bullet,0)

if impact=object1shield
dec object1shield
endif
if impact=object2shield
dec object2shield
endif
.
.
.
.
etc up to

if impact=object50shield
dec object50shield
endif

takes a fair while to type in, now if you use arrays all you tell the computer is that you want to use a variable with a number attached, the number is effectivley part of the variable name, you do it like this

objectshield(4)=12

the tricky bit is that the 4 in the example can be replaced by a variable: eg

objectshield(var)

as long as the variable is within the range of numbers you told the computer to use with the dim statement then you can call them as you wish, using a simple array like this you can do the above code in a few lines

dim objectshield(50)

for i=1 to 50
if object hit(objectshield(i),0)
dec objectshield(i)
endif
next i

that would create and check fifty object numbers for impacts, just like the first code but way easier, you do not have to use them for simple things like that, you can make arrays in 2D

dim twodimensions(100,100)

would make ten thousand numbers placed in a grid 100 across and 100 down, to set the number just use the x and y like this

twodimensions(49,52)=55

this makes a number near the middle of the grid 55, it doesn`t change any of the others, you can make a simple mines game with just that array, make some of the locations 1 and leave the rest at zero, then ask the user where they want to stand , check that position and then blow them up if it`s set to one.

you can have lots of dimensions eg

dim confusing(20,10,22,44,32,78,9)

but I normaly never go over 3 dimensions: eg:

dim localspace(100,100,100) <<<this uses nearly four million bytes (4mb)

remember that multidimensional arrays eat memory at a progresivly faster rate the deeper you make them, and for integers you need four bytes per number, you can use up memory fast with an array, for example that multi dimensional array example I posted above needs about 16 gig .

Mentor.

PC1: P4 3ghz, 1gig mem, 2x160gig hd`s, Radeon 9800pro w cooler (3rd gfx card), 6 way speakers.
PC2: AMD 2ghz, 512mb ram, FX5200 ultra, 16 bit SB.
Mini ATX cases suck.

Login to post a reply

Server time is: 2024-09-22 23:31:50
Your offset time is: 2024-09-22 23:31:50