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 / I guess its time for arrays, help

Author
Message
pc nerd
User Banned
Posted: 4th May 2009 19:51
Ok, ive been trying to avoid arrays becouse i really did not need any. but now that i have pretty much figured out almost every thing i need to figure out for my game engine I need to now know how to set up an array, how to use it in a situation. I have read many diffrent tutts but still am not shure what they do. could someone just please explain it to me in laymans tearms.

dweeb
KISTech
16
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 4th May 2009 21:41
Think of an array as a row of mailboxes.

We'll start with box #1, and let's say there are 10 of them.

To initialize the array,

Dim Mailboxes(10) as integer

This gives you 10 numbers you can associate with those mailboxes.

The real power comes with User Defined Types and Arrays.

Keeping that number doesn't do much for you to identify those mailboxes. So let's expand it a bit.



Now you can put the person's name and address in the fields associated with that mailbox.

Mailbox(1).name = "Robin Hood"
Mailbox(1).address = "4010 Marion Way"

Mailbox(2).name = "Little John"
Mailbox(2).address = "211 Frier Court"

Using for next loops, or counters you have a lot of power to work with.



You don't have to use only strings in User Defined Types either. Those variables can be any data type. Integers, Floats, Bytes, anything.

Hope that helps a little.

pc nerd
User Banned
Posted: 4th May 2009 21:59 Edited at: 4th May 2009 21:59
so Dim Mailboxes(10) as integer would tell the programe there is an array of 10 mailboxes?


this i dont undertand,



then you use something like this to clerify the names of each mailbox?



dweeb
bobbel
15
Years of Service
User Offline
Joined: 5th Jan 2009
Location: In my DBPro case xD
Posted: 4th May 2009 23:22
yes, but don;t forget:

if you do Dim Mailbox(10)
you make an array with eleven mailboxes! cause 0 is also a mailbox!

(\__/)
(O.o )
(> < ) This is Bunny. Copy Bunny into your signature to help him on his way to world domination!
pc nerd
User Banned
Posted: 4th May 2009 23:33
well thanks, this makes a little more sence to me. I think there is alot of difrent math situations in my game where this prosess will come in hand, I will have to practice the array therory to get it down right but I think i understand now. thanks alot

dweeb
feiting shadow
18
Years of Service
User Offline
Joined: 12th Sep 2006
Location:
Posted: 5th May 2009 00:49
http://www.cprogramming.com/tutorial/c/lesson8.html

This might be of better explaining, since they have to explain arrays for the rest of it...

Note that DB doesn't have the aspect where you can only use 0-9 if you declare anArray(10)... you can use 1-10, which is odd, even for BASIC languages (but keeps us from messing up).

Signed
------
pc nerd
User Banned
Posted: 5th May 2009 22:03
well, thanks for that, I read it through and it make alot more sence now. even though its not in dark basic pro it still makes sence.

dweeb
Cagedrei
15
Years of Service
User Offline
Joined: 18th Mar 2009
Location:
Posted: 5th May 2009 22:04 Edited at: 5th May 2009 22:11
Quote: "if you do Dim Mailbox(10)
you make an array with eleven mailboxes! cause 0 is also a mailbox!"


Wow, really? So we can fill the zero 'mailbox' and index the array from zero instead of one? Golly.

If you use empty array() on an array, it is given a count of -1. I guess that fits in with the idea that zero actually counts.

Here, I've just been ignoring that zero slot, and carrying around an extra mailbox in every array! You learn something new all the time, around here. Well, I do....

Edit:
It looks like you can index from zero, but the count is ten mailboxes, not 11. Hmm. But there are actually 11, not ten. So the zeroeth mailbox is unlisted.

AndrewT
17
Years of Service
User Offline
Joined: 11th Feb 2007
Location: MI, USA
Posted: 5th May 2009 22:21
Quote: "It looks like you can index from zero, but the count is ten mailboxes, not 11. Hmm. But there are actually 11, not ten. So the zeroeth mailbox is unlisted."


Array Count() simply returns the index of the highest element, so if there are 11 elements in MyArray() the highest you can access is MyArray(10), therefore Array Count(MyArray()) would return 10.

i like orange
bobbel
15
Years of Service
User Offline
Joined: 5th Jan 2009
Location: In my DBPro case xD
Posted: 5th May 2009 23:46
Glad i could help. i made a difference!

(\__/)
(O.o )
(> < ) This is Bunny. Copy Bunny into your signature to help him on his way to world domination!
feiting shadow
18
Years of Service
User Offline
Joined: 12th Sep 2006
Location:
Posted: 6th May 2009 04:33
heh, I avoided referencing 0 in order to avoid confusion with the whole 11 thing, but yeah, it's a quirk DB has. I've personally come to enjoy it, simplifies things, avoids bugs...

Signed
------
bobbel
15
Years of Service
User Offline
Joined: 5th Jan 2009
Location: In my DBPro case xD
Posted: 6th May 2009 08:39
its not that hard to use. if you had an array for weapons, and a machine gun = 1 and shotgun = 2, just do weapons-1, so you get a zero in the array if its the machine gun and a 1 in the array if its a shotgun.

(\__/)
(O.o )
(> < ) This is Bunny. Copy Bunny into your signature to help him on his way to world domination!
pc nerd
User Banned
Posted: 6th May 2009 18:47 Edited at: 6th May 2009 18:47
Yes bobbel you made a difference! as did KISTech and the rest, thanks guys. I was not going to use this for weapons but for score. I do have many difrent types of games set up for my game, there will be a good 100 difrent jobs, games in my game and im shure I will need arrays in alot of them and setting timmers to all of them will not work. I am experimenting now with arrays and I cant get one to work at all. practise makes perfect i guess.

dweeb

Login to post a reply

Server time is: 2024-11-24 08:19:59
Your offset time is: 2024-11-24 08:19:59