Issue with instance variable and percent sign Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tomdiepstrap
Posts: 4
Joined: 02 Nov 2022, 22:26

Issue with instance variable and percent sign

Post by tomdiepstrap » 03 Nov 2022, 02:20

Hello there, I'm just starting out and I'm having some issues using an instance variable with the ImageSearch method. I've verified that the instance variable is getting correctly set, and the issue seems to lie in actually using it in the call. It works successfully if I copy the value into a local variable and then use that, but if I try to use it as the instance variable, errors abound. I was hoping somebody could point me in the right direction on how to properly formulate the call.

This is the working code below, a local variable is set up and then called with the percent sign notation

Code: Select all

Class shipTargetingAdmin
{
	targetURL := "UNINITIATED"

	...

	searchSector(xIndex, yIndex)
	{
		temporaryURL := this.targetURL
		ImageSearch, FoundX, FoundY, xIndex * A_ScreenWidth / 5, yIndex * A_ScreenHeight / 5, (xIndex+1) * A_ScreenWidth / 5, (yIndex+1) * A_ScreenHeight / 5, *10 *Trans2dff3c %temporaryURL%
		...
		...
		...
	}
}
Below is the code I actually wanted to use, and it makes the compiler rather upset. Specifically: The following variable name contains an illegal character: "this.targetURL"
I've tried every variation I can think of, but they either result in various warnings and errors

Code: Select all

Class shipTargetingAdmin
{
	targetURL := "UNINITIATED"

	...

	searchSector(xIndex, yIndex)
	{
		ImageSearch, FoundX, FoundY, xIndex * A_ScreenWidth / 5, yIndex * A_ScreenHeight / 5, (xIndex+1) * A_ScreenWidth / 5, (yIndex+1) * A_ScreenHeight / 5, *10 *Trans2dff3c %this.targetURL%
		...
		...
		...
	}
}

The full code below, just in case it is relevant

Code: Select all

Class shipTargetingAdmin
{
	targetURL := "UNINITIATED"

	Array := [[2,2],[2,3],[3,2],[1,2],[3,3],[2,4],[4,2],[1,3],[3,1],[1,1],[2,0],[0,2],[4,3],[3,4],[1,4],[4,1],[3,0],[0,3],[1,0],[0,1],[4,4],[4,0],[0,4],[0,0]]

	locateTarget()
	{
		For i, quadrant in this.Array
		{
			coordinates := this.searchSector(quadrant.1, quadrant.2)
			if (coordinates.1 != 0 & coordinates.2 != 0)
				return coordinates
		}
	}


	searchSector(xIndex, yIndex)
	{
		temporaryURL := this.targetURL
		ImageSearch, FoundX, FoundY, xIndex * A_ScreenWidth / 5, yIndex * A_ScreenHeight / 5, (xIndex+1) * A_ScreenWidth / 5, (yIndex+1) * A_ScreenHeight / 5, *10 *Trans2dff3c %temporaryURL%
		;PixelSearch, FoundX, FoundY, xIndex * A_ScreenWidth / 5, yIndex * A_ScreenHeight / 5, (xIndex+1) * A_ScreenWidth / 5, (yIndex+1) * A_ScreenHeight / 5, 0x792c2c, 10, RGB Fast
		if (ErrorLevel = 2)
			MsgBox Could not conduct the search in targeting system.
		else if (ErrorLevel = 0)
		{
			return [FoundX, FoundY]
		}
		else
		{
			return [0, 0]
		}
	}

	SetTargetURL(inputURL)
	{
		this.targetURL := inputURL
	}
	
	GetTargetURL()
	{
		return this.targetURL
	}
	
}

User avatar
boiler
Posts: 17404
Joined: 21 Dec 2014, 02:44

Re: Issue with instance variable and percent sign  Topic is solved

Post by boiler » 03 Nov 2022, 02:39

You can only put % signs around simple variables. You can force an expression for that parameter and use the instance variable directly:

Code: Select all

ImageSearch, FoundX, FoundY, xIndex * A_ScreenWidth / 5, yIndex * A_ScreenHeight / 5, (xIndex+1) * A_ScreenWidth / 5, (yIndex+1) * A_ScreenHeight / 5, % "*10 *Trans2dff3c " . this.targetURL

tomdiepstrap
Posts: 4
Joined: 02 Nov 2022, 22:26

Re: Issue with instance variable and percent sign

Post by tomdiepstrap » 03 Nov 2022, 14:02

Ahh, but of course! I got so close to that too, but I think I missed the . for the concat. Thank you very much, your solution worked perfectly

User avatar
boiler
Posts: 17404
Joined: 21 Dec 2014, 02:44

Re: Issue with instance variable and percent sign

Post by boiler » 03 Nov 2022, 17:56

tomdiepstrap wrote:
03 Nov 2022, 14:02
Ahh, but of course! I got so close to that too, but I think I missed the . for the concat. Thank you very much, your solution worked perfectly
The . for the cooncat is optional, so you must have missed something else. I’m guessing you missed the % to force an expression.

tomdiepstrap
Posts: 4
Joined: 02 Nov 2022, 22:26

Re: Issue with instance variable and percent sign

Post by tomdiepstrap » 04 Nov 2022, 01:29

No I definitely tried that before, but perhaps I missed the quotation marks for the parts that weren't variables. Either way, thanks again

Post Reply

Return to “Ask for Help (v1)”