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.

DarkBASIC Discussion / what is the usefullness of arrays?

Author
Message
gpex
19
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 25th Jun 2005 11:44
I know that this question must seem rediculous to some but i need a little help understanding the ue or arrays and why i would use them. I know the syntax and how to use it but i dont know when i would use and array instead of seperate variables. The reason i'm asking this is because they must be very usefull because i see lots of people use them in their code, so an explanation would be great.


-gpex-

Your signature has been erased by a mod because it is larger than 600x120...
Mattman
21
Years of Service
User Offline
Joined: 5th Jun 2003
Location: East Lansing
Posted: 25th Jun 2005 12:21 Edited at: 25th Jun 2005 12:22
They keep groups of information together with ease. For example, if I was to keep the data for my tile-based map in an array, I could make a big array, lets say 50 X tiles by 50 Z tiles for my map. To create the array we would code

DIM map(50,50)

Now instead of making lots of different variables for every tile, it is held in one big array. Let's say we want to make a wall at 20,30. Let's make walls 1.

map(20,30) = 1

Now the entry 20,30 inside the map array has a value of 1. The example may be a big confusing as I didn't go into a structure of how you would keep that kind of data for a tile based map, but hopefully you got how you can keep a large amount of data inside of an array for speed and ease of use

Matt

God nobody reads signatures nowadays.
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 25th Jun 2005 12:47 Edited at: 25th Jun 2005 15:45
gpex,

For another example, they are useful when you need to create the effect of a player shooting bullets, as in an FPS. The properties of a bullet may include angle,xpos,ypos,speed and bulletlife. If one were using all seperate variables, he would have to write seperate chunks of code to edit the positions of each bullet.

However, when using an array, the bullets properties can all be reached in just one chunk of code, using a for next, repeat until or while endwhile loop. Look below for a sample of a section of code which makes an 'active' bullet to move, given its properties.




+NanoBrain+
gpex
19
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 25th Jun 2005 14:34
well, i understand a little better, i'll keep working with them. Thanks for the help.

Your signature has been erased by a mod because it is larger than 600x120...
Underworld 1020
21
Years of Service
User Offline
Joined: 2nd Mar 2004
Location: NY, USA
Posted: 26th Jun 2005 08:08 Edited at: 26th Jun 2005 08:08
Here this should help: (taken from the DBC help menus)



gpex
19
Years of Service
User Offline
Joined: 29th May 2005
Location:
Posted: 26th Jun 2005 15:42
oooohhhh...i should have just read the help files(though your comments did help), that would make a lot more sense to use arrays. Thanks for all who replied.


-gpex-

Your signature has been erased by a mod because it is larger than 600x120...

Login to post a reply

Server time is: 2025-05-22 21:47:31
Your offset time is: 2025-05-22 21:47:31