Changing Global Variable Not Working! Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
A random guy
Posts: 31
Joined: 10 Feb 2017, 19:55

Changing Global Variable Not Working!

14 Mar 2017, 17:55

Sorry for being so stupid, but why doesnt this script work!!?? I making it so the script displays a message when lol = 1. When the script gets i message from a another script then i want it to change the variable to whatever the Wparam is.

Code: Select all

Lol = 0
OnMessage(0x5577, "Test")
Loop
{
if Lol = 1
{
msgbox, 4144, test, test
}
}

Test(wParam)
{
Lol := %Wparam%
}
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Changing Global Variable Not Working!

14 Mar 2017, 18:38

The Test() function has it's own scope.
Lol is in the global scope.

Either declare Lol as global in Test (Which will allow test to see outside it's own scope to the global version of test)

Code: Select all

Test(wParam)
{
global Lol
Lol := %Wparam%
}
or make Lol "Super Global"
As Lol is already global, prefixing it with global makes it super global, meaning it can be seen from everywhere
global Lol = 0
A random guy
Posts: 31
Joined: 10 Feb 2017, 19:55

Re: Changing Global Variable Not Working!

14 Mar 2017, 19:40

Sorry but that doesnt work. It stills sets it as a local variable for test
A random guy
Posts: 31
Joined: 10 Feb 2017, 19:55

Re: Changing Global Variable Not Working!  Topic is solved

14 Mar 2017, 19:52

Ok I Got it! I had to change Lol := %wParam% to Lol = %wParam% and now it works perfectly

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], joedf, scriptor2016, supplementfacts and 138 guests