VarRef of object parameters

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
kheless
Posts: 1
Joined: 27 Jun 2022, 12:12

VarRef of object parameters

Post by kheless » 27 Jun 2022, 12:19

Hello,

I have issue to deal with VarRef with instance parameters. In the ImageSearch I use local variables then I reatribute value to the parameters. Is there a way to get the VarRef of parameter like :

Code: Select all

ImageSearch( &Frame.FoundX, &Frame.FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, TSFrameTitlePath ) 
I have the working following code but it's a bit dirty :

Code: Select all

#Requires AutoHotkey v2.0-beta
WindowTitle := "FrameName"
#HotIf WinActive(WindowTitle)
TSFrameTitlePath := "D:\Modding\Scripts\Auto\FrameTitle.bmp"

;Parameters
TSFrame := {}
TSFrame .FoundX := 0   ;311
TSFrame .FoundY := 0   ;168
TSFrame .FirstItemDX := 22   ;289
TSFrame .FirstItemDY := 177   ;345
TSFrame .CreateDX := 224   ;535
TSFrame .CreateDY := 603   ;771


SetFrameParameters(&TSFrame)
SelectFirstElement(&TSFrame)

SelectFirstElement(&Frame)
{
	if( Frame.FoundX != 0 && Frame.FoundY != 0) 
		MouseMove((Frame.FoundX+Frame.FirstItemDX), (Frame.FoundY+Frame.FirstItemDY))
	else
		MsgBox("Woops.")
}

SetFrameParameters(&Frame)
{
	WinActivate(WindowTitle)
	
	;Frame location and widgets location
	LFoundX := 0
	LFoundY := 0
	try
	{
		if( !ImageSearch( &LFoundX, &LFoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, TSFrameTitlePath) )
			MsgBox("TSFrame not opend.")
		else
			Frame.FoundX := LFoundX
			Frame.FoundY := LFoundY
	}
	catch as exc
	    MsgBox("Could not conduct the search due to the following error:`n" exc.Message)

}

lexikos
Posts: 9560
Joined: 30 Sep 2013, 04:07
Contact:

Re: VarRef of object parameters

Post by lexikos » 27 Jun 2022, 21:58

No. VarRef represents a variable, not a property (what you referred to as an "instance parameter"). Other kinds of references might be supported in future.

In your working code, there is no need to use & with TSFrame or Frame, as you are not assigning to Frame itself.

Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: VarRef of object parameters

Post by Helgef » 01 Jul 2022, 03:06

Code: Select all

{
	if( !ImageSearch( &LFoundX, &LFoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, TSFrameTitlePath) )
		MsgBox("TSFrame not opend.")
	else
		Frame.FoundX := LFoundX
		Frame.FoundY := LFoundY
}
You should use else { ... }. (Indentation has no effect on blocks, unlike python, for example)

Cheers.

Post Reply

Return to “Ask for Help (v2)”