Values of variables not persistent Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Cyrano
Posts: 12
Joined: 29 Mar 2023, 17:03

Values of variables not persistent

Post by Cyrano » 01 Apr 2023, 12:03

In this script, it seems to me that the first MsgBox output confirms that the mouse coordinates are being captured and assigned to variables Temp_X and Temp_Y as intended.

When I attempt to use these variables in a subsequent Click operation, the second MsgBox output shows the variables have reverted to their as-initialized values.

What am I doing wrong?

TIA,
Tony

Code: Select all

DetectHiddenWindows(true)
SetTitleMatchMode 3
#HotIf WinActive("ahk_exe uedit64.exe", )
CoordMode("Mouse", "Screen")
CoordMode("Pixel", "Screen")
#SingleInstance Force
DetectHiddenText False
DetectHiddenWindows False

Temp_X := 0
Temp_Y := 0

^t:: 
{
MouseGetPos  &Temp_X, &Temp_Y
MsgBox  "Temp_X  = "  Temp_X "   " "Temp_Y = " Temp_Y
return
}

t::
{
MsgBox  "Temp_X  = "  Temp_X "   " "Temp_Y = " Temp_Y
Click Temp_X,  Temp_Y
return
}

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Values of variables not persistent  Topic is solved

Post by swagfag » 01 Apr 2023, 12:07

u skipped the chapter on functions and scope https://www.autohotkey.com/docs/v2/Functions.htm#Local

in fact ure better off reading the whole thing to to bottom

Cyrano
Posts: 12
Joined: 29 Mar 2023, 17:03

Re: Values of variables not persistent

Post by Cyrano » 01 Apr 2023, 12:38

swagfag wrote: u skipped the chapter on functions and scope ...
I've skipped many chapters, alas.

I'm not a developer, but I managed to use AHK v1 for my needs. AHK v2 seems much more powerful and complex than v1. Consequently, to write useful code in v2 requires having much more understanding of fundamental programming concepts than was necessary to use v1.

If I want to use v2 effectively, it appears I will have to spend many hours reading and digesting the documentation in a systematic manner.

Post Reply

Return to “Ask for Help (v2)”