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 / Arrays "HELP"

Author
Message
learner
16
Years of Service
User Offline
Joined: 7th Mar 2009
Location:
Posted: 8th Mar 2009 22:29
Can anyone give me a numbskulls guide to arrays?.
I just can`t seem to grasp these.

Thanks
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 9th Mar 2009 01:23 Edited at: 9th Mar 2009 02:02
The purpose of an array is to store a collection of one type of data that aren't numerically related; i.e. your player's HP is unlikely to have any numerical relation to his Experience Points, they're both totally independent, so you need two variables to store them, and that's all an array is; a group of variables.

The advantage of an array is organisation; say we have an array called store(20), imagine it as a filing cabinet with one draw and 21 folders with numbered tags 0-20 (don't forget about 0). We can put whatever we like in these "folders" (or "fields") and it will stay there until we change it or UNDIM the array.
Because we are so organised it's really easy to get hold of our data, just call the array with the numbered field we want, e.g. PRINT store(2), assigning values to our fields is just as easy: x= store(5).

So instead of having 21 variables (don't forget 0) called something like store0,store1,store2,... (and having to hard code everything that uses any of them) we now have a nice orderly array that makes it so much simpler to find and edit the data we need.

But we've just been talking about a one dimensional array, you can have multiple dimensions.
Let's get rid of our boring store array and make something more interesting like a map for our new project (the next big MMORPG perhaps? ).
To make a 2D map we'll need a 2D array (makes sense), DIM map(7,7) creates our very own 8x8 map (you forgot about 0 didn't you). To visualise this; instead of folders think now of a grid, like one you'd see on errrm... a map! Each column and row is numbered and every square on the map contains data that we can reference using the column and row numbers, i.e. map(0,4) would be on the first row, four columns accross.
Now where-ever our character goes we can find out what number is in that square by referencing the square at his position map(playerx,playery). These numbers could be all sorts of things maybe different terrain types; e.g. 1=sand, 2=water, 3=grass.

PS you can call your arrays whatever you like just remember to dimension them before trying to use them.

Does that help?

The Universe has been erased by a mod because it was larger
than 240x80 pixels.
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 9th Mar 2009 02:21
also check out:

array tutorial

Enjoy your day.
learner
16
Years of Service
User Offline
Joined: 7th Mar 2009
Location:
Posted: 10th Mar 2009 00:15
At last the light has dawned
Thanks very much.
Oh,and i did`nt forget 0.........Honest
learner
16
Years of Service
User Offline
Joined: 7th Mar 2009
Location:
Posted: 11th Mar 2009 22:49
In my programme i want the user to input a number up to 100.
How can i get the programme to accept only even numbers?.

Thanks

Login to post a reply

Server time is: 2025-05-16 11:18:27
Your offset time is: 2025-05-16 11:18:27