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 need more help guys, some one explain array for me!

Author
Message
DBasic Khan
20
Years of Service
User Offline
Joined: 3rd Dec 2003
Location: Alpha Quadrent, Sector 1,1 SOL SYS
Posted: 12th Jan 2004 20:39
Once again i give up. I am trying to figure out out arrays work. Im not too impressed by the help files explination of it. Could some one p[lease just take the time and give me a detailed list on how they work, what to use em form, anything ya think will be helpful.
Emperor Baal
20
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 12th Jan 2004 21:03 Edited at: 12th Jan 2004 21:09
Arrays are like variables, but can hold multiple things. Example:

dim Example(1000)

for A = 0 to 1000
example(A)=A
next A

this will make an array that can hold 1001 integers, the for next loop fills the array with integers, so
example(0) = 0
example(1) = 1
etc.


Why do you want to use arrays?

If you want to make a strategy game, you may want to use:

dim Unit_Health(999)

so you can store the health of 1000 units.
Thats much better than:

Unit_one_health=10
Unit_two_health=10
etc etc etc

But this is also possible:

dim Unit_Position#(999,2)

for a=0 to 999
Unit_Position#(a,0)=object position x(a)
Unit_Position#(a,1)=object position y(a)
Unit_Position#(a,2)=object position z(a)
next a


Now its up to you, you can use thousand variables or just a single array.


How to use them

DIM makes a new array

DIM array_name(amount)

To put a thing (integer/float/string/etc) into an array is an easy task, its just like using variables

DIM array_name(100)

array_name(index_number)=value

just replace index_number and value with numbers and that value is stored in that array_name(index_number)

the index_number ranges from 0 to *the number you used to DIM it*
in this case
( DIM array_name(255) )
it would be 0-255


Quote: "
Amd 2500+ | 1024mb pc2700 | A7N8X-X | Geforce4 ti 4200 128mb
"
Chris K
20
Years of Service
User Offline
Joined: 7th Oct 2003
Location: Lake Hylia
Posted: 12th Jan 2004 22:53
Think of it like boxes.

dim MyFirstArray(3,3,2)

This like three boxes, each of these has three more boxes in and each of those boxes has two boxes in. The smallest boxes can store information.



To set an array you need to tell what boxes to go to -

MyFirstArray(2,1,2) would be this box:



Ian T
22
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 13th Jan 2004 00:30
If it helps...

dim array(2)

array(0), array(1) and array(2) will now be at your disposal for use as seperate variables. You could use a loop to fill these 3 variables in only 3 lines of code instead of doing it all manually.

--Mouse: Famous (Avatarless) Fighting Furball

I am the chainsaw paladin.
comando 300
20
Years of Service
User Offline
Joined: 23rd Nov 2003
Location:
Posted: 13th Jan 2004 00:37
Arrays are globals

Is just of those days when you don't wanna wake up everything is *****, everybody sucks you really don't know why, but you wanna justify rippin' someone head off!
QuothTheRaven
21
Years of Service
User Offline
Joined: 2nd Oct 2002
Location: United States
Posted: 13th Jan 2004 03:16
Wow. None of these posts are really going to help you. At all.

An array is a bunch of numbers in one place. That place is a variable called an array

There are two types of arrays, 1 dimensional and 2 dimensional.

A one dimensional array, is like a line of numbers. It goes in one direction.

Like Array Bob could contain
5,6,7,8,9,10

and to get something out of Bob, you go to the position in Bob. The first position of Bob is 5. So Bob(1) is 5. Bob(2) is 6. And so on.

But that's only a 1 dimensional array. Your array could be 2 dimensional

Array Bob could look like
5,4,3,2,1
1,2,3,4,5
9,8,7,6,5
2,3,4,5,6

Bob is a 4 by 5 array. It has 4 rows of numbers and 5 columns. See, it's like a rectangle. You can change how many rows and columns there are, making the rectangle different shapes.

Bob(1,1) is 5. It's the first row and the first column.
Bob(2,1) is 4.
Bob(2,2) is 2.

And it's all just a rectangle of numbers that you can pull positions from. That said, an array can hold a vast amount of information.

That's a basic intro to them, the concept at least.

Philip
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: United Kingdom
Posted: 13th Jan 2004 15:03
@Quoth

The first position of an array is array(0), not array(1).

Also, I believe that DB Pro supports up to five dimensional arrays. So, for example, you could have: dim quoth(10,43,100,2,6)

Philip

What do you mean, bears aren't supposed to wear hats and a tie? P1.3ghz / 384 megs / GeForce MX 5200 128meg / WinXP home
Emperor Baal
20
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 13th Jan 2004 17:07
Only mouse and comando300 were correct. Array-Index numbers start at 0 not 1 (Yeah, it sucks).

So
" Wow. None of these posts are really going to help you. At all."

would be

" Wow. None of these posts are really going to help you. At all. Even this one"


Quote: "
Amd 2500+ | 1024mb pc2700 | A7N8X-X | Geforce4 ti 4200 128mb
"
BadMonkey91
20
Years of Service
User Offline
Joined: 13th Jan 2004
Location:
Posted: 13th Jan 2004 19:02
I don't know much about Darkbasic, since I just started working with it around a week ago, but in previous languages I've used, I've found that arrays can be explained like this;

for A = 1 to 100
Position object 1, A, 10, 0
next A

That is how I always used to move objects (not the "position object" command exactly, but simmilar commands)

Badmonkey91@hotmail.com
Mentor
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 13th Jan 2004 19:54


Mentor.

System spec : Pentium 3.0Ghz, 512MB DDR, 2x160Gb HD (using icewave hd coolers ), DVD RW/CD RW (all modes), multimedia front panel, 6 way surround sound, ATI radeon 9800Pro 128mb.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 13th Jan 2004 20:13
lol @ mentor.

BadMonkey - that's not an array you described there. That is a variable being incremented by a For-Next Loop.

-RUST-

DBasic Khan
20
Years of Service
User Offline
Joined: 3rd Dec 2003
Location: Alpha Quadrent, Sector 1,1 SOL SYS
Posted: 13th Jan 2004 20:24
Thanks A million, this all realy helped me!!!!!!!!!!!!!!1

Login to post a reply

Server time is: 2024-09-21 15:46:26
Your offset time is: 2024-09-21 15:46:26