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 / variable scope

Author
Message
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 18th Mar 2017 15:39
I had always been under the impression that when I create a variable that it only exists within the control loop it was created within. This does not seem to be the case with AppGameKit and was wondering if this is a bug or intentional? If I define a variable inside a loop structure, shouldn't it NOT exist anywhere else outside of that structure?

For instance:


"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 18th Mar 2017 16:41
i believe c# handle it so and agk use the function scope.
AGK (Steam) V2017.02.28 : Windows 10 Pro 64 Bit : AMD (17.2.1) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 18th Mar 2017 21:38
Yes, i think the scope is bound to the function() or main. Not loops
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 20th Mar 2017 08:46
Yep, AppGameKit follows BASIC rules, not OOP rules. Variables exist in whatever function (Or not in the case of the main program before any functions are called)
They are NOT scoped by loops etc.
Signature removed by mod because it's larger than 600x120... please resize and try again.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 20th Mar 2017 09:35 Edited at: 20th Mar 2017 09:36
Unless your variables are declared as global, or arrays. They can be accessed from anywhere.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 20th Mar 2017 21:15
i think arrays are only global when you use DIM to create them (unless you use global)
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 20th Mar 2017 21:24
Oh yes. You're right. I swear I read somewhere something about arrays being global, but I just wrote a little test and confirmed in fact they are not. I'll keep quiet in future. Lol.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 20th Mar 2017 21:41
You were correct! If you use DIM to define it then the array is global
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Mar 2017 01:50
Arrays used to be global by default, agk2 changed that with the new definitions

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2024-04-26 20:56:39
Your offset time is: 2024-04-26 20:56:39