Window Won't Stop At Y Cord 700. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
UnAlpha
Posts: 3
Joined: 22 Apr 2018, 23:02

Window Won't Stop At Y Cord 700.

22 Apr 2018, 23:06

I'm building my first script; an active window gravity script.

Essentially, the active window will keep falling until it hits the Y cord 700, and it will just stop. That's the idea at least.
(Eventually, I will make it not hardcoded to 700, but that's after I get help with this issue.)

However, there's a problem, which I got no idea how to fix:
Once the active window reaches the Y cord 700, it just keeps going, rather than stopping in place.

Here's my code:

Code: Select all

ScriptName = GRAVITY SCRIPT

InputRestriction = false
SetBatchLines, -1
SetWinDelay, 0


GRAVITY = 1

while true
{	
	if InputRestriction = true
	{
		WinGetActiveStats, Title, Width, Height, X, Y
		WinWait, %Title%
		
		
		if(%Y% + 1 <= 700)
		{
			WinMove, WinGetPos X, WinGetPos Y + 1
		}
	} 
}

; debug stuff, irrelevant
~Esc::
KeyWait, Esc
if InputRestriction = true
{
	InputRestriction = false
	MsgString := "Script is paused."
	MsgBox, 0, %ScriptName%, %MsgString%
}
else if InputRestriction = false
{
	InputRestriction = true
	MsgString := "Script is resumed."
	MsgBox, 0, %ScriptName%, %MsgString%
}
return

~Left::
KeyWait, Left
WinGetActiveStats, Title, Width, Height, X, Y
MsgBox, %X% %Y%
return
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Window Won't Stop At Y Cord 700.  Topic is solved

23 Apr 2018, 04:47

if(%Y% + 1 <= 700)
You are double-dereferencing Y.
You used brackets for the IF, so you are already in expression syntax.
If y holds 750, %Y% is trying to check the value of a VARIABLE called 750, which does not exist.

You want if(Y + 1 <= 700)
UnAlpha
Posts: 3
Joined: 22 Apr 2018, 23:02

Re: Window Won't Stop At Y Cord 700.

23 Apr 2018, 17:15

Hey, your fix worked. Thank you so much.

Also, I have a question about your second post. I do not understand why this is invalid syntax as it is operating as expected without errors.

Thank you for the help.
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Re: Window Won't Stop At Y Cord 700.

24 Apr 2018, 03:16

Code: Select all

		WinGetActiveStats, Title, Width, Height, X, Y	; Sets X/Y
		WinWait, %Title%
		
		
		if(%Y% + 1 <= 700)
		{
			WinMove, WinGetPos X, WinGetPos Y + 1 ; Uses X/Y. Also uses empty "WinGetPos" variable
		}
Because WinGetPos is interpreted as a variable, which does not exist, so it resolves to "".
So because X and Y actually are set, it tries to add "" to x or y, which does not alter x or y.
UnAlpha
Posts: 3
Joined: 22 Apr 2018, 23:02

Re: Window Won't Stop At Y Cord 700.

24 Apr 2018, 14:53

Ah, I understand now.

I've changed the code and removed the WinGetPos to see this first hand and it doesn't change the behavior.

Thank you for taking the time to explain this to me.

Here is the altered code for anyone who may be curious:

Code: Select all

ScriptName = GRAVITY SCRIPT

InputRestriction = false
SetBatchLines, -1
SetWinDelay, 1


GRAVITY = 1

while true
{	
	if InputRestriction = true
	{
		WinGetActiveStats, Title, Width, Height, X, Y
		WinWait, %Title%
		SysGet, VirtualHeight, 79
		
		if(Y + 1 <= VirtualHeight - VirtualHeight / 10)
		{
			WinMove, X, Y + 1
		}
	} 
}

; debug stuff, irrelevant
~Esc::
KeyWait, Esc
if InputRestriction = true
{
	InputRestriction = false
	MsgString := "Script is paused."
	MsgBox, 0, %ScriptName%, %MsgString%
}
else if InputRestriction = false
{
	InputRestriction = true
	MsgString := "Script is resumed."
	MsgBox, 0, %ScriptName%, %MsgString%
}
return

~Left::
KeyWait, Left
WinGetActiveStats, Title, Width, Height, X, Y
MsgBox, %X% %Y%
return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, ShatterCoder and 116 guests