Functions not calling Topic is solved

Ask gaming related questions (AHK v1.1 and older)
Smilie
Posts: 2
Joined: 18 Jan 2019, 05:17

Functions not calling

18 Jan 2019, 05:21

Hi,
I have a very basic script, that simply moves and clicks with the mouse in order to drop some items, but for some reason, nothing happens when i press ctrl + d, or ctrl + s.

Code: Select all

YCoords := [370, 398, 432, 456, 488]
DropCoordX := 234
DropCoordY := 313
DropItem(x, y)
{
	MouseMove, x, y
	Click
	MouseMove, DropCoordX, DropCoordY
	Click
}
DropFirst()
{
	x := 490
	while (x < 640)
	{
		for index, element in YCoords
		{
			DropItem(x,element)
		}
		x += 30
	}
}
DropSecond()
{
	x := 640
	while (x <= 790)
	{
		for index, element in YCoords
		{
			DropItem(x,element)
		}
		x += 30
	}
}

^d::
DropFirst()
return

^s::
DropSecond()
return
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Functions not calling

18 Jan 2019, 06:12

functions have scope, YCoords at the top and YCoords in ur for-loops dont refer to the same thing
u need to make YCoords available to the function. u can use the global keyword or pass it to the function as an argument
read more: https://www.autohotkey.com/docs/Functions.htm
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Re: Functions not calling  Topic is solved

18 Jan 2019, 16:54

Yeah, each function you create is local by default so it can only access values you define in function itself.
as swag said do this:

myFunction(x,y)
{
global
my code
return
}

Now it can access not only x,y but all other variables you created (except variables from functions that are local).
Smilie
Posts: 2
Joined: 18 Jan 2019, 05:17

Re: Functions not calling

18 Jan 2019, 17:37

Thanks man, that did the trick! :D

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 102 guests