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.

Author
Message
HZence
23
Years of Service
User Offline
Joined: 9th Mar 2003
Location:
Posted: 23rd Nov 2003 01:54
I was wondering how one might declare a global variable (which can be used and altered in all functions) in DarkBASIC Pro?

Team EOD :: Programmer/Storyboard Assistant
CloseToPerfect
23
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 23rd Nov 2003 01:58
GLOBAL variable_name

Lifes short, try to enjoy it and not take it to seriously!
HZence
23
Years of Service
User Offline
Joined: 9th Mar 2003
Location:
Posted: 23rd Nov 2003 02:00
What the he11? I swear I tried that among other things, such as #GLOBAL (and even #UNIVERSAL, lol).

Thanks CTP

Team EOD :: Programmer/Storyboard Assistant
spooky
23
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 23rd Nov 2003 02:00
Also, remember that arrays are global anyway as default, so you can use them within functions without any special code.


Boo!
HZence
23
Years of Service
User Offline
Joined: 9th Mar 2003
Location:
Posted: 23rd Nov 2003 02:22 Edited at: 23rd Nov 2003 02:25
Okay, rather than start a new thread, I'll just ask my question here. Why can't I declare a global variable within a function and have it work in every other function? While it may seem like it works, it doesn't. Here's what happened.

1. I had three functions: VARIABLES(), DISPLAY_MENU(), and CONTROL_MENU().
2. Within the VARIABLES() function, I declared (but did not initialize) the variable ButtonOver.
3. In the DISPLAY_MENU() function, I have a DO loop. Within this do loop, there are many instances in which ButtonOver's value can be changed, mostly by the user putting their mouse over a button I have. Within the DO loop (all code within the function is in the DO loop) I call CONTROL_MENU(). In the CONTROL_MENU() function it is vital that I read the value of ButtonOver. I did this the first time to have it not work. So, obviously analyzing my code and run-time for errors, I use the code center text 50, [y position], "ButtonOver: " + str$(buttonover). I found that in the DISPLAY_MENU() function, the variable is altered, yet when CONTROL_MENU() is called, either the variable is reset or it has not been globally altered.
4. When I tried declaring ButtonOver at the top of my program (NOT within a function), I did not have this problem and the variable was globally altered.

Any ideas? Could this be a...

*dum dum dum*

Bug?!

Team EOD :: Programmer/Storyboard Assistant
CloseToPerfect
23
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 23rd Nov 2003 02:59
this used to work, I'm sure, but I just wrote a snippet for it and it's not? I wonder if 5.1 broke it?

CTP

Lifes short, try to enjoy it and not take it to seriously!
HZence
23
Years of Service
User Offline
Joined: 9th Mar 2003
Location:
Posted: 23rd Nov 2003 03:38
hmm, i'll post about it in bug reports.

Team EOD :: Programmer/Storyboard Assistant
feiting
22
Years of Service
User Offline
Joined: 19th Oct 2003
Location:
Posted: 23rd Nov 2003 03:58
use subs not funcs. Static vars are not supported and all func variables are local by nature. if it is like c++ then global is just an int declared before the main loop with no special indicator that it is global. The same exact "int n" in a func would be local, but a subroutine is like a macro and out of any function.

He who does not take the assassin job, will get killed by one who does.
HZence
23
Years of Service
User Offline
Joined: 9th Mar 2003
Location:
Posted: 23rd Nov 2003 04:39
point is, it used to work, and now it doesn't. lol. i don't use subs instead of functions because i for one dislike spaghetti code.

Team EOD :: Programmer/Storyboard Assistant
CattleRustler
Retired Moderator
22
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 23rd Nov 2003 05:24
erm,

GLOBAL intX as Integer

-RUST-

Login to post a reply

Server time is: 2026-07-26 19:46:49
Your offset time is: 2026-07-26 19:46:49