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.

Newcomers DBPro Corner / Muti Dimensional Arrays

Author
Message
PanouleXxX
21
Years of Service
User Offline
Joined: 24th Mar 2003
Location:
Posted: 24th Mar 2003 21:37
I am a beginner. I am thirsty to learn how to use DarkBAIC in order o make up my 3D Games. So I started reading the Introduction but I have a problem...
I cannot understand the Multi Dimendional Arrays. I saw the example but i could not understand it. Could you please explain to me the Multi Dimensional Arrays?
If you can please give me an example...


Thanx :-s
The Darthster
22
Years of Service
User Offline
Joined: 25th Sep 2002
Location: United Kingdom
Posted: 25th Mar 2003 01:42
Multidimensional arrays are a useful way of holding lots of attributes of objects in your game, although that is not their only use.

Say you have an army of 20 soldiers, to group their attributes together you'd want to use an array to keep the variable names neat, and allow you to use for...next indexing. Each of these 20 soldiers has 5 limbs (pretty rubbish soldier model, but still). For each of these 5 limbs you want to store 6 values, x, y, z, and the 3 angles. To do this you would create a 3 dimensional array, DIM soldier(20,5,6). The first dimension contains the index number of the soldier you are referencing. The second dimension contains the index number of the limb you are manipulating. The third dimension contains the actual variables corresponding to the positions and variables. Note all this is conceptual, to the computer these variables will just appear as numbers, you have to manually set things using the variables in the arrays. You would do this using for...next loops:

for i=0 to 19
for j=0 to 4
offset limb i,j,soldier(i,j,0),soldier(i,j,1),soldier(i,j,2)
rotate limb i,j,soldier(i,j,3),soldier(i,j,4),soldier(i,j,5)
next j
next i

Ok, now another way to use multidimensional arrays - for map coordinates. You can create an array with 2 dimensions the size of the map you are trying to portray. Then, you can simply use the index numbers as map coordinates, and set heights and tiles and stuff at that specific map coordinate.

Dim map(10,10)
data 0,0,0,0,0,0,0,0,0,0
data 0,1,0,1,0,0,0,0,0,0
data 0,0,2,0,0,0,0,0,0,0
data 0,1,0,1,0,1,0,0,0,0
data 0,0,0,0,1,2,1,0,0,0
data 0,0,0,1,2,3,2,1,0,0
data 0,0,1,2,3,4,3,2,1,0
data 0,0,0,1,2,3,2,1,0,0
data 0,0,0,0,1,2,1,0,0,0
data 0,0,0,0,0,1,0,0,0,0
for i=0 to 9
for j=0 to 9
read map(j,9-i)
set matrix height 1,j,i,map(j,9-1)*100
next j
next i

Note that code was made up, it may not actually work, but gives an impression of how you could use it.

Hope that helped.

Once I was but the learner,
now, I am the Master.
JD UK
21
Years of Service
User Offline
Joined: 28th Mar 2003
Location:
Posted: 29th Mar 2003 05:10 Edited at: 29th Mar 2003 05:15
I read at DBheaven.com that the arrays start at 0 and you should use the 0 positions in the array to save memory? So the soilder array should be (19,4,5)? or didnt i understand the dbheaven tutoial correctly ?

Danmatsuma
21
Years of Service
User Offline
Joined: 2nd Mar 2003
Location: Australia
Posted: 29th Mar 2003 11:49 Edited at: 29th Mar 2003 12:00
That's true but I wouldn't worry too much about that, unless your machine is very low-spec.
You can leave the 0 position empty, as it's a bit hard to use it with objects when they start at 1.

But that said, you are starting in the right place, arrays are cool, they make life easier if you learn how to map them out and write your game around that map

You might do something like:



Your array map should be drawn on paper first and look something like:


soldiers#(soldier,posinfo#[3 slots])
slot 1=xpos#
slot 2=ypos#
slot 3=zpos#

soldiers(soldier,liveordead[1 slot])
slot 1=1 for alive, 0 for dead

So you left slot 0 free for something else.

and you can just keep adding slots for more info, using the float array for float values, and the int array for int values. More dimensions come into play when you want to neaten things up, but get your head around the basics first

to use that info, like to find out where youre soldiers went:



ZX Spectrum 48k Issue 3, Radio shack Tape drive, Rank arena 12" T.V. set.

Login to post a reply

Server time is: 2024-11-24 09:07:58
Your offset time is: 2024-11-24 09:07:58