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 Professional Discussion / Question about array's and functions

Author
Message
Dragon slayer
19
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 20th Nov 2012 23:49
This is out of the DBP Guide

Quote: "
OK, earlier I said that in DB, global variables don't officially exist. Well they don't, but there is a work-around
you can use if necessary.
It turns out that arrays declared using DIM in your main program are sort of global in so much as you can see
them inside functions, alter their contents inside the function and the alterations are intact in your main
program when you exit the function!
This gives us a very nifty way around the fact that you can only pass a single variable back from a function.
With arrays we have no need to pass more than one as we can use arrays.
Arrays declared inside a function however are still local and are destroyed on exit. They cannot be seen on
return to the main program. Also, as they are destroyed when exiting the function, you can DIM an array at the
start of a function and call it many times without getting an 'Array Already Dimensioned' error. You don't have
to 'Undim' as you would in the main program.
This also conveniently gets around the limitation mentioned earlier that you cannot have an array in the
parameter list you pass to a function. Now you don't need to as the array can be seen and modified inside the
function anyway!"


So how do you do this? I know the guide is kind of old and I am sure some things have changed but how would you modify an array that is outside a function from within a function?

Thanks
Dragonslayer
Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 21st Nov 2012 00:17 Edited at: 21st Nov 2012 00:19
If the ARRAY is defined prior to the functions where you want to use it, then it's visible and accessible inside every function that follows it.

ie


Dragon slayer
19
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 21st Nov 2012 01:39
So if you want to fill the array with different values you would list them here separated by a , Table(lp) = ThisValue?
tiresius
23
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 21st Nov 2012 04:05
What guide is that? And is it for DBPro? Globals exist in DBPro and can be declared.

Dragon slayer
19
Years of Service
User Offline
Joined: 3rd Nov 2006
Location: Bourbonnais Illinois
Posted: 21st Nov 2012 13:19
It is called the beginners guide to DBP written by NickyDude. It is somewhat dated but still pretty good. You can Get it here if you want to check it out.

http://forum.thegamecreators.com/?m=forum_view&t=137027&b=7
tiresius
23
Years of Service
User Offline
Joined: 13th Nov 2002
Location: MA USA
Posted: 22nd Nov 2012 06:40
That includes TDK tutorials which are for Darkbasic not Darkbasic Professional. Maybe it isn't that big of a deal but the languages are different in some areas. For instance, it says strings cannot be larger than 255 characters, which isn't true in DBPro.

Login to post a reply

Server time is: 2026-07-10 16:22:40
Your offset time is: 2026-07-10 16:22:40