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 / Your One-Stop Shop For Array's

Author
Message
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 14th Jan 2004 09:11
Hello,

Ok... I'm not too sure how many people will read this, or how many people it will help, but here it is anyway...

Ever wanted a good explination of array's? Ever wanted to know how they work? Don't think the Help Files are descriptive enough? Well, you've come to the right place!!


I don't think I've ever used an array and if I have then I don't know what it is. That's one thing that the Help Files don't really explain that well.

Ok..

An Array can basically be seen as a fileing cabinet.
Lets say in this fileing cabinet you had two draws, as an array that would represent;

Dim myarray(2)
Note: ( The Dim command just sets the array, you only ever use it once )\

Now lets say that in each draw, you had 5 folders, then the array would be;

Dim myarray(2,5)
Note: ( The 2 is the amount of draws, and the 5 is the amount of folders )

Then, lets say that each folder has in it another 3 folders, the array would now be;

Dim myarray(2,5,3)

And so on...


Ok I get that, But how do I access the array?

Let's say you wanted to acces the 2nd subfolder of the 4th folder in the first draw ( That's the same as going, ok, open the first draw, look for the 4th folder, now i want the 2nd subfolder )
To access that you use

variable = myarray(1,4,2)
Note: I didn't use the Dim command, because i am not setting the array, just accessing it's values

So, what does that help when I'm programming?

Well, ok, now that you have each draw, and each draw has the four folders, and each of these folders has the three subfolders...

Think about how many sub folders there is all up, that's 3 for each folder, so there's 4 folders in the first draw, that means there's 3 x 4 subfolders in that draw, that's 12 subfolders in the first draw, and the same in the second draw, that gives you 24 subfolders all up.

Tt's much easier to have all of that set up in the fileing cabinet rather than having them all spread out on the floor ( ie, all in seperat variables ), isn't it?

Ah, I see

That's the benifit of array's

So much better than having all these other variables floating around when all you need is a single array.


Hope I Helped anyone in need of an explanation of array's.

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 14th Jan 2004 09:27 Edited at: 14th Jan 2004 09:28
Its always good to explore arrays.

If you really think your A pro now at arrays and you want to hurt your brain with a 5 dimensional array setup then consult this example.


[href]www.lunarpixel.net/media/db_code_snippets/indi_5d_array_example.zip
[/href]
Emperor Baal
21
Years of Service
User Offline
Joined: 1st Dec 2003
Location: The Netherlands - Oudenbosch
Posted: 14th Jan 2004 10:28
Haha, but a good explanation of arrays would tell you that they start with (0) not with (1).




Quote: "
Amd 2500+ | 1024mb pc2700 | A7N8X-X | Geforce4 ti 4200 128mb
"
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 14th Jan 2004 12:15
@Indi, nice example.

@Emperor Baal, I never really said anything much about what values were available, and I didn't particularily want to go into too much detail as this was meant for those that aren't familiar with array's.

And also, I have noticed that some people that aren't too good with arrays tend to get confused when you tell them that the array starts at 0.

Having said that, I thank you for your input.

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Travis
21
Years of Service
User Offline
Joined: 9th Nov 2003
Location: West Aust.
Posted: 15th Jan 2004 03:01
Thats why i sometimes just pretend they begin at one or whatever... there just slots to fill u dont needa fill them all and one slot thats not being used cant waste to much memeory
Mattman
21
Years of Service
User Offline
Joined: 5th Jun 2003
Location: East Lansing
Posted: 15th Jan 2004 20:24
they start at 0? that good to know

a
Brandon Smith
21
Years of Service
User Offline
Joined: 19th Oct 2003
Location: Urbana, Illinois (USA)
Posted: 16th Jan 2004 01:02
I was just wondering,
is it possible to send an array to function in DarkBASIC classic?
I couldn't find anything in the Help about it, it would be really cool if this were possible.

Thanks,
Brandon
Mattman
21
Years of Service
User Offline
Joined: 5th Jun 2003
Location: East Lansing
Posted: 16th Jan 2004 05:08
nope

a
JoelJ
21
Years of Service
User Offline
Joined: 8th Sep 2003
Location: UTAH
Posted: 16th Jan 2004 05:59
functions are global...you dont need to pass them

indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 16th Jan 2004 07:36
dont you mean arrays declared at the top of your program are global?
Brandon Smith
21
Years of Service
User Offline
Joined: 19th Oct 2003
Location: Urbana, Illinois (USA)
Posted: 16th Jan 2004 08:59 Edited at: 16th Jan 2004 09:14
Yes that's true. But whenever I use arrays as gloabal variables in a file, I can't include that file in other programs, that was my only problem. I was hoping to be able to decalre arrays inside a function and then pass it to other functions. Otherwise you'd be right, I wouldn't need to send them to a function.

And thanks Mattman, I just wanted to make sure.

Brandon
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 16th Jan 2004 09:33
the include file is series of functions therefore not the top or global hence localised.

Login to post a reply

Server time is: 2025-05-22 05:57:51
Your offset time is: 2025-05-22 05:57:51