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.

AppGameKit Classic Chat / GLOBAL and Local Variables

Author
Message
XanthorXIII
AGK Gold Backer
12
Years of Service
User Offline
Joined: 13th May 2011
Location:
Posted: 16th Aug 2011 07:51
I've seen how to declare Global variables. Can I do the same with local or do I need to use a different keyword?
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 16th Aug 2011 09:58
Variables should be local by default, no need to explicitly declare them as such. (However, it seems to be bugged at the minute)

My signature is NOT a moderator plaything! Stop changing it!
LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 16th Aug 2011 14:47
Hi, The local keyword is not used in AppGameKit, and is only implied when you are inside a function. All variables outside of a function are treated as global (whether or not you use the GLOBAL keyword).

I drink tea, and in my spare time I write software.
XanthorXIII
AGK Gold Backer
12
Years of Service
User Offline
Joined: 13th May 2011
Location:
Posted: 16th Aug 2011 15:24
So any variable I declare inside my main.agc is automatically Global and if I declare one inside a function it is treated as local?
LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 19th Aug 2011 01:58
Yes, you got it.

I drink tea, and in my spare time I write software.
XanthorXIII
AGK Gold Backer
12
Years of Service
User Offline
Joined: 13th May 2011
Location:
Posted: 27th Aug 2011 17:34
Lee,
Sorry to say it but this doesn't work. You have to declare it as Global otherwise it crashes the program when you try to make function calls.
Just have to keep that in mind.
Thanks.
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 27th Aug 2011 20:30
Lee - it seems like the auto-assigned ID numbers for resources are NOT global when created.

For instance

mySprite = CreateSprite(myImage)

generates a sprite ID that is not global, and crashes the program when called in a function.

Redostrike
21
Years of Service
User Offline
Joined: 9th Feb 2003
Location: Belgium
Posted: 27th Aug 2011 21:02
Even if they are global without declare its a good habit of just declaring every variable you use! I know local does not need to be declare and you actully cannot declare them but what i do is i rem them in the functions. rem local temp as integer. Just to have a reminder for myself which variables i'm already using.

Only heroes live forever
MobileCreator
12
Years of Service
User Offline
Joined: 1st Jun 2011
Location: Ottawa - Canada
Posted: 28th Aug 2011 05:51
The only way I could set and use global variables properly, like a sprite ID is actually use the Global keyword.

When I do not use it, AppGameKit thinks it is two different variables.

Cheers

Paulo

Login to post a reply

Server time is: 2024-05-06 19:17:01
Your offset time is: 2024-05-06 19:17:01