Code acting weirdly, or is it just me

Ask gaming related questions (AHK v1.1 and older)
ry3ks3u_m4dd0ns
Posts: 18
Joined: 29 Mar 2017, 09:23

Code acting weirdly, or is it just me

07 Apr 2017, 18:49

So, if you couldn't tell from the annoying title, I'm having trouble again.

I've made a script for a Facebook game called 'Ninja Saga' where the script allows for quick casting of jutsus and talents.
And I've added a variable called ScriptStasis where if its 1, the script would go into stasis (duh),and that's where sh*t hits the fan hard.

For some unknown reason, since I've added If statements on each auto cast function to check for ScriptStasis, the script would acknowledge its value, but run the function INFINITELY,even though the purpose of ScriptStasis is to allow me to use the key as intended. Autohotkey even warned me that the script sent 71 hotkeys in the last 1129ms.

Here's the code for anyone who would like to help me:

Code: Select all

#CommentFlag ==>
#SingleInstance FORCE
#MaxThreadsPerHotkey 1
CoordMode, Mouse, Screen
ScriptStasis := 0

==> //-----Actions-----//
Jutsu_1()
{
	If ScriptStasis = 0
	{
		ControlClick, x484 y489, Facebook Gameroom
	} else
	{
		Send, 1
	}
}
Jutsu_2()
{
	If ScriptStasis = 0
	{
		ControlClick, x525 y489, Facebook Gameroom
	} else
	{
		Send, 2
	}
}
Jutsu_3()
{
	If ScriptStasis = 0
	{
		ControlClick, x567 y489, Facebook Gameroom
	} else
	{
		Send, 3
	}
}
Jutsu_4()
{
	If ScriptStasis = 0
	{
		ControlClick, x606 y489, Facebook Gameroom
	} else
	{
		Send, 4
	}
}
Jutsu_5()
{
	If ScriptStasis = 0
	{
		ControlClick, x744 y489, Facebook Gameroom
	} else
	{
		Send, 5
	}
}
Jutsu_6()
{
	If ScriptStasis = 0
	{
		ControlClick, x784 y489, Facebook Gameroom
	} else
	{
		Send, 6
	}
}
Jutsu_7()
{
	If ScriptStasis = 0
	{
		ControlClick, x824 y489, Facebook Gameroom
	} else
	{
		Send, 7
	}
}
Jutsu_8()
{
	If ScriptStasis = 0
	{
		ControlClick, x865 y489, Facebook Gameroom
	} else
	{
		Send, 8
	}
}
Talent_1()
{
	If ScriptStasis = 0
	{
		ControlClick, x654 y251, Facebook Gameroom
	} else
	{
		Send, Numpad1
	}
}
Talent_2()
{
	If ScriptStasis = 0
	{
		ControlClick, x616 y289, Facebook Gameroom
	} else
	{
		Send, Numpad2
	}
}
Talent_3()
{
	If ScriptStasis = 0
	{
		ControlClick, x616 y333, Facebook Gameroom
	} else
	{
		Send, Numpad3
	}
}
Talent_4()
{
	If ScriptStasis = 0
	{
		ControlClick, x654 y369, Facebook Gameroom
	} else
	{
		Send, Numpad4
	}
}
Talent_5()
{
	If ScriptStasis = 0
	{
		ControlClick, x695 y369, Facebook Gameroom
	} else
	{
		Send, Numpad5
	}
}
Talent_6()
{
	If ScriptStasis = 0
	{
		ControlClick, x732 y333, Facebook Gameroom
	} else
	{
		Send, Numpad6
	}
}
Talent_7()
{
	If ScriptStasis = 0
	{
		ControlClick, x732 y289, Facebook Gameroom
	} else
	{
		Send, Numpad7
	}
}
Talent_8()
{
	If ScriptStasis = 0
	{
		ControlClick, x695 y251, Facebook Gameroom
	} else
	{
		Send, Numpad8
	}
}
AutoOk()
{
	If ScriptStasis = 0
	{
		ControlClick, x763 y499, Facebook Gameroom
	} else
	{
		Send, 0
	}
}
MissionOk()
{
	If ScriptStasis = 0
	{
		ControlClick, x971 y449, Facebook Gameroom
	} else
	{
		Send, -
	}
}
Separateddddddd()
{
	Suspend
	ToolTip % A_IsSuspended ? "Script suspended" : "Script reenabled"
return
}

==> //-----Keybinds-----//
1::Jutsu_1()
2::Jutsu_2()
3::Jutsu_3()
4::Jutsu_4()
5::Jutsu_5()
6::Jutsu_6()
7::Jutsu_7()
8::Jutsu_8()
0::AutoOk()
-::MissionOk()
Numpad1::Talent_1()
Numpad2::Talent_2()
Numpad3::Talent_3()
Numpad4::Talent_4()
Numpad5::Talent_5()
Numpad6::Talent_6()
Numpad7::Talent_7()
Numpad8::Talent_8()

F1::
	ScriptStasis:=!ScriptStasis
	Tooltip, %ScriptStasis%
	Sleep, 250
	Tooltip
return

ESC::
	Suspend
	ExitApp
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Code acting weirdly, or is it just me

07 Apr 2017, 18:58

Put

Code: Select all

#UseHook
at the top of your script

or

put $ prefix on your hotkeys.
ry3ks3u_m4dd0ns
Posts: 18
Joined: 29 Mar 2017, 09:23

Re: Code acting weirdly, or is it just me

07 Apr 2017, 19:01

Xtra wrote:Put

Code: Select all

#UseHook
at the top of your script

or

put $ prefix on your hotkeys.

For the ScriptStasis variable problem? Yeah, THAT, I could've done if it was the main problem, but it's not.

My real problem is that even when the script realizes it shouldn't execute the code inside of the first brackets of If statement, it executes the second part like it's New Years.
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Code acting weirdly, or is it just me

07 Apr 2017, 19:26

I think you missed the point.

Your functions are activating the hotkeys in a endless loop.

HTH
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Code acting weirdly, or is it just me

07 Apr 2017, 19:32

Also note the line at the top of script:

Code: Select all

ScriptStasis := 0
Should be:

Code: Select all

Global ScriptStasis := 0
This will make it super global and the variable usable in the functions.
ry3ks3u_m4dd0ns
Posts: 18
Joined: 29 Mar 2017, 09:23

Re: Code acting weirdly, or is it just me

07 Apr 2017, 19:55

Xtra wrote:Also note the line at the top of script:

Code: Select all

ScriptStasis := 0
Should be:

Code: Select all

Global ScriptStasis := 0
This will make it super global and the variable usable in the functions.
I'm even more confused.
Nightwolf85
Posts: 302
Joined: 05 Feb 2017, 00:03

Re: Code acting weirdly, or is it just me

07 Apr 2017, 20:55

Xtra is correct, in each of your functions you are checking the value of ScriptStasis, but you are checking a local copy of that variable. If you use the Global prefix when initializing the variable it will be considered a Super Global and functions will use the right value to check. Basically the IF checks will always fail because an un-initialized variable ( A blank string I believe "" ) will never equal 0. Other option is to declare it global in each function, but since you use it in every one the Super Global option is your best one.
https://autohotkey.com/docs/Functions.h ... _Variables
https://autohotkey.com/docs/Functions.htm#SuperGlobal

**Edit
Also on his other point read about it here, you need to use the $ prefix or #UseHook because your hotkeys are triggering themselves.
https://autohotkey.com/docs/Hotkeys.htm#prefixdollar
ry3ks3u_m4dd0ns
Posts: 18
Joined: 29 Mar 2017, 09:23

Re: Code acting weirdly, or is it just me

07 Apr 2017, 21:13

Nightwolf85 wrote:Xtra is correct, in each of your functions you are checking the value of ScriptStasis, but you are checking a local copy of that variable. If you use the Global prefix when initializing the variable it will be considered a Super Global and functions will use the right value to check. Basically the IF checks will always fail because an un-initialized variable ( A blank string I believe "" ) will never equal 0. Other option is to declare it global in each function, but since you use it in every one the Super Global option is your best one.
https://autohotkey.com/docs/Functions.h ... _Variables
https://autohotkey.com/docs/Functions.htm#SuperGlobal

**Edit
Also on his other point read about it here, you need to use the $ prefix or #UseHook because your hotkeys are triggering themselves.
https://autohotkey.com/docs/Hotkeys.htm#prefixdollar

Alright, I'm done with other stuff than this script, so I'll try it out.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 82 guests