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 / What good are functions if you can't call global variables from within them

Author
Message
sgalland
22
Years of Service
User Offline
Joined: 18th Nov 2002
Location: United States
Posted: 13th May 2004 09:11
Greetings,

I was wondering what good are functions if you cannot call a global variable from within them. I understand you can pass arguments like C++ or any other programming language, but if I want to code a menu I need a lot of components setup as functions and its hard if you can only call global variables if they are called as arguments, to me its not very flexible. Anyone have any suggestions on what to do in order to make calling functions more flexible?
zenassem
22
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 13th May 2004 10:01 Edited at: 13th May 2004 10:16
You could just have a return variable and set your global to equal that value.

I know in c++ you can pass by value or reference, and sometimes it's nice to have the option. But it's best to handle it the way DB is set up. This way I am certain that I can give my function to anyone, and regardless if they have a global variable with the same name somewhere in their program, it won't mess up the data.

IF It's Really Important to you... Use the DarkEdit IDE for DBC
(DarkEdit is much better than the original editor anyway, and is more akin to DBpro's editor.)

Turn on the extended commands in the options.
then.


will ouput.
15
35

where as the same code minus the "unavailable" global command in the default editor will ouput.
15
15

hope that helps.

~zen[b]

BearCDPOLD
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: AZ,USA
Posted: 13th May 2004 10:16
Another solution (DarkEdit does this automatically for you, so it's better just to use DarkEdit). Arrays are completely global, can be used anywhere. Dark Edit converts all your

GLOBAL Myvar stuff to

DIM Myvar(0)

Crazy Donut Productions, Current Project: KillZone
Web Site Button Does Not Work, Visit Here: http://www.geocities.com/crazydonutproductions/index.html
sgalland
22
Years of Service
User Offline
Joined: 18th Nov 2002
Location: United States
Posted: 13th May 2004 11:22
cool, thanks for the help!

Login to post a reply

Server time is: 2025-05-23 19:00:51
Your offset time is: 2025-05-23 19:00:51