AutoHotkey Community

It is currently May 27th, 2012, 8:07 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Variable scope
PostPosted: January 4th, 2007, 9:23 pm 
Offline

Joined: November 25th, 2006, 9:02 am
Posts: 13
Quote:
If you declare a variable at the start of your script and outside any functions it exists in the Global scope and can be read or changed from anywhere in the script.
If you declare a variable inside a function it is in Local scope and can only be used within that same function. Variables created inside functions are automatically destroyed when the function ends.

(from "AutoIt Language Reference")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2007, 11:16 pm 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
... So what's your request?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2007, 11:25 pm 
Offline

Joined: November 25th, 2006, 9:02 am
Posts: 13
Quote:
To refer to an existing global variable inside a function (or create a new one), declare the variable as global prior to using it.

(from AutoHotkey Help)

Can anyone just notice any difference?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 4th, 2007, 11:28 pm 
Offline

Joined: November 13th, 2004, 4:08 am
Posts: 2951
Location: Minnesota
It would be nice if you would state it clearly. Are you saying that inside a function, references should first go to global variables?

And keep in mind that in AutoIt, you have to declare variables before you use them. In AutoHotkey, you don't. This key difference affects the way variables have to be treated.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 5th, 2007, 1:50 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
There is a plan to have superglobals that are visible inside any function. Although it increases flexibility, it does so at the cost of purity and maintainability. But on balance, it seems better to have it than not have it.

I'm not sure when this will get implemented. It might be after AutoHotkey version 2.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 23rd, 2007, 7:47 pm 
Quote:
And keep in mind that in AutoIt, you have to declare variables before you use them. In AutoHotkey, you don't. This key difference affects the way variables have to be treated.
. LOL Thats totally wrong. Autoit has an option which can be set so you NEED to declare a variable before use. But it is not defualt.


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 8 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group