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.

Newcomers DBPro Corner / No Globals???

Author
Message
GMX
19
Years of Service
User Offline
Joined: 19th Sep 2005
Location: In front of my monitor
Posted: 18th Oct 2006 02:39
Are you kidding me? No global variables?

Not to be mean or anything, but C++ has them, and even Blitz Basic and Game Maker have global variables. How can a language that is so easy to use yet powerful like darkBASIC not have global variables?

So is there a way to get around that? Any technique that pros use?

ZOMG
David iz cool
19
Years of Service
User Offline
Joined: 21st Sep 2005
Location: somewhere lol :P
Posted: 18th Oct 2006 03:49 Edited at: 18th Oct 2006 03:49
im pretty sure any variable u use can be used anywhere else in your code,thus making it global.
Gil Galvanti
19
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 18th Oct 2006 04:21
no, they can't be used in functions unless passed, but yes, you can declare global, lol, it's as easy as saying:
"GLOBAL variable"
That gets you a global variable .

Pirates of Port Royale
Live the life of a pirate.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 18th Oct 2006 05:14
In Darkbasic Pro you can have globals. Or you can cheat with arrays... arrays are always global.


GMX
19
Years of Service
User Offline
Joined: 19th Sep 2005
Location: In front of my monitor
Posted: 19th Oct 2006 00:25
my gosh, I never knew any of this. I read in the manual that there weren't any global variables, was I wrong?

And arrays are always global? Amazing, I had no idea.

Then again, I am a newbie

ZOMG
2D Analyst
AGK Developer
20
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 19th Oct 2006 04:21
I thought there is global. Even the syntax GLOBAL shows up

www.simpoware.com
Gil Galvanti
19
Years of Service
User Offline
Joined: 22nd Dec 2004
Location: Texas, United States
Posted: 19th Oct 2006 04:27
Quote: "I thought there is global. Even the syntax GLOBAL shows up"

erm...it might help if you read the other 3 posts that answered the question

Pirates of Port Royale
Live the life of a pirate.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 19th Oct 2006 05:15
"Global" only works in Pro. In Enhanced it does show up as a command but running it produces an error. Arrays are global in all Darkbasics.
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 19th Oct 2006 15:10
You can use Global with darkEdit.. which comes with DBC... or atleast with mine

Roxas
18
Years of Service
User Offline
Joined: 11th Nov 2005
Location: http://forum.thegamecreators.com
Posted: 19th Oct 2006 20:55
Yea in DB classic use arrays and in pro use command



jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 19th Oct 2006 23:33 Edited at: 19th Oct 2006 23:34
I do not want to pick at this thread, but GLOBAL is a type modifier, not a command, or variable. It simply places the variable it modifies at a global scope...it can be seen everywhere, including within functions that are in the same module that they are...which in DBPro, should be the entire program.

I think that arrays are global in all BASICs.
GMX
19
Years of Service
User Offline
Joined: 19th Sep 2005
Location: In front of my monitor
Posted: 20th Oct 2006 00:08 Edited at: 20th Oct 2006 00:08
Quote from DBPro manual:

Quote: "Functions are blocks of commands that usually perform a recursive or isolated task that is frequently used
by your program. Variables and arrays used within the function are isolated from the rest of the program. If
you use a variable name of FRED in your function, it will not affect another variable called FRED in your
main program, nor any other function that happens to use a similar variable name. This may seem to be a
restriction, but forces you to think about cutting up your program into exclusive tasks which is a very
important lesson."


??? But yet global shows up as a keyword (blue and bold) in the editor. So I can just declare a variable to be global and I'll be able to use it in functions? I know that's what globals do, but are regular, non-array variables in darkBASIC able to be accessable to any part of the program? I understand I can just use pointers for this, but it would be so much easier to just be able to use global variables.

ZOMG
jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 20th Oct 2006 02:26
Well, I use the global type modifier...which shows up in blue...I use it like this:

global total_syncs as integer
global fileName as string

I can freely modify them or access them anywhere I want within my program. I think that people are not using the global modifier, that is why they cannot "see" the variable inside of function calls, for example.

The syntax highlighting means what you think it does...yes, it works that way. I am not sure that you can make much use of pointers outside of memory blocks, and even then...they are messy and not very simple to implement.

Also, local is another keyword that you can use inside functions to prevent the scope error when variables have the same name. Judicious use of both will prevent the scope errors that plague programmers in BASIC sometimes. (Too many is, for example.)
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 20th Oct 2006 02:48
Quote: "But yet global shows up as a keyword (blue and bold) in the editor. So I can just declare a variable to be global and I'll be able to use it in functions?"


Jinzai is right. If you can run this without it causing an error then yes you can use globals. Try running it.



Does it work or does it say "Syntax Error. Unknown command at line 1"?

Quote: "I know that's what globals do, but are regular, non-array variables in darkBASIC able to be accessable to any part of the program?"


Regular non-array variables can't be accessable inside functions but you can send one into a function and get it back changed... but it can only return one variable.

Dracula
18
Years of Service
User Offline
Joined: 7th Aug 2006
Location: DBP Recreation of Castle Csejthe
Posted: 20th Oct 2006 03:42
I knew there were Globals and I didn't even read the manual...

fun fun

D
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 20th Oct 2006 15:34
I think this goes to show how much the poster looked into the problem at hand.

GMX
19
Years of Service
User Offline
Joined: 19th Sep 2005
Location: In front of my monitor
Posted: 21st Oct 2006 08:14 Edited at: 21st Oct 2006 08:14
For some reason, I remember typing global and it didn't work...then I went to the manual and saw that it said that. I guess not, but that's why I posted here instead. No need to be sarcastic

ZOMG
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 21st Oct 2006 08:51
theres no sarcasm in that post.

Login to post a reply

Server time is: 2024-09-25 11:19:33
Your offset time is: 2024-09-25 11:19:33