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 / global variables

Author
Message
mathkid
20
Years of Service
User Offline
Joined: 1st Feb 2005
Location: Central Massachusetts
Posted: 20th Feb 2005 21:03
Is the global command only for DBPro? I've seen it on the forums, but whenever I use it in DBC, the compiler doesn't recognize it.

If that's the case, is it possible to declare global variables in DBC without using arrays?
mathkid
20
Years of Service
User Offline
Joined: 1st Feb 2005
Location: Central Massachusetts
Posted: 22nd Feb 2005 00:59
Someone has to know about this. Doesn't anyone use global variables?
TKF15H
21
Years of Service
User Offline
Joined: 20th Jul 2003
Location: Rio de Janeiro
Posted: 22nd Feb 2005 01:22
Just initialize the variable at the top of your program (outside a function) and it should be global.

Variable=0

no need for the Global keyword.

AphoticVM status: 30% (Yes, that number just went down.) AphoticBasic status: 10%
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 22nd Feb 2005 02:43
Lmao this isn't C++, you can't do that. Globals don't exist in DBC.


"Lets migrate like bricks" - Me
NanoBrain
20
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Portland, OR
Posted: 22nd Feb 2005 03:37
To all,

Global does exist in DBC, but only as an array.
For example:
DIM variable(1,2)
variable(1,1) = 1
variable(1,2) = 1

In decalring a variable this way, at the top of your program and outside a function, you have created a global variable, able to be used inside and outside functions and throughout your program, even in #INCLUDE files.

+NanoBrain+
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 22nd Feb 2005 03:53
Er yeah, I forgot that..


"Lets migrate like bricks" - Me
hyrichter
21
Years of Service
User Offline
Joined: 15th Feb 2004
Location: Arizona
Posted: 22nd Feb 2005 03:53
Nano got it right. Whenever I need a global variable in DBC I just declare an array with an index of zero:

DIM MyGlobal(0)

empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 22nd Feb 2005 04:01
I think mathkid knew that option. That would explain his sentence:
"If that's the case, is it possible to declare global variables in DBC without using arrays?"

But apart from the array work-around, there's no way of declaring global variables in DBC.


Play Nice! Play Basic! Version 1.06
Benjamin
22
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 22nd Feb 2005 04:14
Theres no point in smiling about it...


"Lets migrate like bricks" - Me
mathkid
20
Years of Service
User Offline
Joined: 1st Feb 2005
Location: Central Massachusetts
Posted: 22nd Feb 2005 04:49
Thanks everyone. hyrichter, your tip is a really good idea. I was trying to find a way to make global variables without using huge arrays ( like player position = somearray(37) ) and I think that will work just fine.

Login to post a reply

Server time is: 2025-05-23 21:36:13
Your offset time is: 2025-05-23 21:36:13