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 Variable in a Function

Author
Message
Teckno
21
Years of Service
User Offline
Joined: 20th Jan 2004
Location: Inside of your computer, LET ME OUT!!!!!
Posted: 4th Feb 2004 19:01
How do I (or can I) declare a globle variable in a function?

I am god, now bow before me you stupid peasants
I accept no responsibility for any thing I say while... well..... ever
Ralen
21
Years of Service
User Offline
Joined: 22nd Jul 2003
Location:
Posted: 5th Feb 2004 04:09
function test()
global a
endfunction


You are better off declaring globals at the beginning of your program. Its not really a great idea to declare them at random locations through out your code, because that will make it harder to debug later.

Ralen
Teckno
21
Years of Service
User Offline
Joined: 20th Jan 2004
Location: Inside of your computer, LET ME OUT!!!!!
Posted: 5th Feb 2004 04:21
a is the variable, right?

what do you mean by declaring globals at the beginning of the program?

I am god, now bow before me you stupid peasants
I accept no responsibility for any thing I say while... well..... ever
Teckno
21
Years of Service
User Offline
Joined: 20th Jan 2004
Location: Inside of your computer, LET ME OUT!!!!!
Posted: 6th Feb 2004 07:32
There must be some way to get a function to alter an variable outside of the function.

I am god, now bow before me you stupid peasants
I accept no responsibility for any thing I say while... well..... ever
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 6th Feb 2004 07:46
like this perhaps




Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 6th Feb 2004 13:32
But, as you are using DBC, you have to have DarkEDIT, and turn on the extended syntax commands in the options menu. Specifically the one that says "Globals", lol.

You have to do this, as DBC doesn't natively have globals, and DarkEDIT converts all instances of that global variable to an array so that it is global.

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy
Teckno
21
Years of Service
User Offline
Joined: 20th Jan 2004
Location: Inside of your computer, LET ME OUT!!!!!
Posted: 6th Feb 2004 21:10
its working now!!! thank you so much

however, now when the program starts a 0 runs down the side of the screen, how do i stop it?

and whats with the message thingy I get when compile and execute? Its not a big problem but its alittle annoying

I am god, now bow before me you stupid peasants
I accept no responsibility for any thing I say while... well..... ever
Teckno
21
Years of Service
User Offline
Joined: 20th Jan 2004
Location: Inside of your computer, LET ME OUT!!!!!
Posted: 6th Feb 2004 21:23
nevermind about the 0 thingy, I found the problem

I am god, now bow before me you stupid peasants
I accept no responsibility for any thing I say while... well..... ever
Jess T
Retired Moderator
21
Years of Service
User Offline
Joined: 20th Sep 2003
Location: Over There... Kablam!
Posted: 7th Feb 2004 11:00
The message is a popup by DarkEDIT telling you that it has converted all of your Global commands to array's. You can't get rid on it unfortunatly.

Jess.


Team EOD :: Programmer/Logical Engineer/All-Round Nice Guy

Login to post a reply

Server time is: 2025-05-22 11:31:05
Your offset time is: 2025-05-22 11:31:05