Local variables must not be declared in this function

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
rengg
Posts: 4
Joined: 27 Jan 2017, 22:17

Local variables must not be declared in this function

21 Oct 2017, 17:47

Code: Select all


someClassMethod() {
	ControlGetPos, x, y,,, SomeControl
	local someVar := 5
}
If i declare/initialize the local variable before ControlGetPos then there is no error. Trying to figure out why.
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Local variables must not be declared in this function

21 Oct 2017, 18:09

Assume-global mode: If a function needs to access or create a large number of global variables, it can be defined to assume that all its variables are global (except its parameters) by making its first line either the word "global" or the declaration of a local variable.
source:Assume-global mode
(my underline)

[EDIT] Unless the first line of the function's body is, either the word "global" or the declaration of a local variable, your function behaves by default in a "assume-local mode" in such a way that declare your variable as local thereafter is superfluous; hence the "Local variables must not be declared in this function".
my scripts
SirRFI
Posts: 404
Joined: 25 Nov 2015, 16:52

Re: Local variables must not be declared in this function

22 Oct 2017, 05:18

Variables defined within any function/method are local and won't be remembered when it ends. If You want it to be remembered between calls, use static this.variable (only for class instances).
Use

Code: Select all

[/c] forum tag to share your code.
Click on [b]✔[/b] ([b][i]Accept this answer[/i][/b]) on top-right part of the post if it has answered your question / solved your problem.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: arrondark and 117 guests