How to use control variables while restricting them to class scope?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Psyese
Posts: 3
Joined: 30 Jul 2021, 15:04

How to use control variables while restricting them to class scope?

Post by Psyese » 01 Jul 2022, 01:25

Hello!

I am unable to get past the error:"A control's variable must be global or static". My requirement is that the scope of control variables be limited to the class (cannot be global withing file scope), but at the same time be accessable for outside functions. How do I do that?

Code: Select all

class panel
{
	check1ON := False
	check2ON := False
	check3ON := False
	check4ON := False
	check5ON := False
	generate_gui()
	{
		WinGet, gamewindow_handle, ID, % gamewindow
		Gui, +AlwaysOnTop -SysMenu +Owner%gamewindow_handle%
		Gui, Add, Text, , % "Enable checks:"
		Gui, Add, CheckBox, vcheck1ON, % "Check 1"
		Gui, Add, CheckBox, vcheck2ON, % "Check 2"
		Gui, Add, CheckBox, vcheck3ON, % "Check 3"
		Gui, Add, CheckBox, vcheck4ON, % "Check 4"
		Gui, Add, CheckBox, vcheck5ON, % "Check 5"
		Gui, Add, Button, w80, % "Calibrate"
	}

	toggle_panel()
	{
		if WinExist("Script control panel")
			Gui, Hide
		else
		{
			Gui, Show, NoActivate , % "Script control panel"
		}
		return
	}
}

debug()
{
	MsgBox, % panel.check1ON
	return
}
This, or course, produces the aforementioned error.

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

Re: How to use control variables while restricting them to class scope?

Post by swagfag » 16 Jul 2022, 12:49

u can ditch ahk-v1, fire up ahk-v2 and the headaches will surely stop

but back ontopic, how do u use them control variables? u dont, simple as. give the controls ure creating HWNDs, store the HWNDs somewhere(eg as instance variables), then use GuiControl/GuiControlGet along with the HWNDs to read/write the controls' "variables"

Post Reply

Return to “Ask for Help (v1)”