Need syntax help with break command

Ask gaming related questions
Rioa
Posts: 5
Joined: 29 Oct 2019, 02:19

Need syntax help with break command

29 Oct 2019, 02:40

Hi, just had a quick simple question:

is there a way to hit a hotkey and have it break from all running loops?

I have several scripts for a video game involving mouse clicks; once in a while a mouse click is skipped over and then my game starts freaking out because instead of navigating menus, now my camera is swinging all over the place trying to get the mouse click to the center of the screen. Some of these scripts are fairly lengthy taking up to like 10 seconds; in an intense battle with enemies this is insanely annoying if i accidentally bump the wrong hotkey.

I have several brute force workaround solutions ready to go -- but a hotkey::breakall would be amazing and take a fraction of the effort, just looking for the correct syntax, if it exists.

P.S. every forum i read everyone keeps falling back on ::ExitApp like some kinda crutch; i dont want my script to terminate because then i need to alt tab and restart it -- I was contemplating running two scripts (one off to the side that could reboot the main script) but again, it would just be so much easier to run one script with some kinda breakall clause.
User avatar
Xtra
Posts: 1992
Joined: 02 Oct 2015, 12:15

Re: Need syntax help with break command

29 Oct 2019, 05:14

Take a look at: Reload
Rioa
Posts: 5
Joined: 29 Oct 2019, 02:19

Re: Need syntax help with break command

29 Oct 2019, 17:13

tried your suggestion in many various syntaxs, but it looks like the problem still exists -- it's performing things like ::exitapp and ::reload AFTER the last stack call (e.g. it wont exitapp/reload until it's had a 'complete' freakout), and then it will roll onto other hotkeys snippets that were pressed during the freakout, in chronological order. What I need is something that can break from a loop being executed by another method/function mid loop... kind of like an external/global ::while command. Trying your reload idea made me painfully aware i cant utalize several of my brute force ::exitapp methods either

I'm beginning to assume I need to embed a termination-clause WITHIN every lengthy function.

This time i included my whole script, lengthy as it is, to see if anything is preventing other functions from working properly

P.S. now im thinking the optimal strategy might be doing something like having a <break> function statement at the beginning of all lengthy functions. Again i would need some syntax help but i was thinking the psuedocode would be something like the following:

Code: Select all

;+++++++++++++++++++++++++++++++
;enter jewel farm event
pgdn::
                             ;new psuedocode -- I also dont know exact syntax 
                             Do While (f11 != pressed) ... Else (Break)
	;start
	send, e

	;post a new quest
	click, 200, 133
	sleep, 2000
        ...
        ...
        ...
;+++++++++++++++++++++++++++++++
This is kind of a crappy brute force method, but i have a strong suspicion with enough tinkering I could implement that loop termination clause successfully, but again, I would love to have a global command to affect all functions at once with a single keystroke (during a call stack) to cause a break. The following is my full script in its entirety (obviously disregard the f11 key at the bottom)


Code: Select all

;---------------------------------------------------------------------------------------------------

#maxThreadsPerHotkey, 2
setKeyDelay, 50, 50
setMouseDelay, 50

autoclicker = 1
toggleswitch = 0

f10::ExitApp

;=======================Number pad shortcuts=================
;keypad 0 - bomb
Numpad0::
	Send, {f7}
	Sleep, 250
	send, {6}{7}{8}
	Send, {f5}
return

;keypad 1 - atk buff
Numpad1::
	Send, {f8}
	Sleep, 250
	send, 1
	Send, {f5}
return

;keypad 2 - def buff
Numpad2::
	Send, {f8}
	Sleep, 250
	send, 2
	Send, {f5}
return

;keypad 3 - cloak
Numpad3::
	Send, {f7}
	Sleep, 250
	send, 5
	Send, {f5}
return

;keypad 4 - heal fountain
Numpad4::
	Send, {f8}
	Sleep, 250
	send, 4
	Send, {f5}
return

;keypad 5 - Nulberry
Numpad5::
	Send, {f8}
	Sleep, 250
	send, 5
	Send, {f5}
return

;keypad 6 - canteen
Numpad6::
	send, e
	sleep, 750
	send, e
	sleep, 750
	send, {Down}
	sleep, 750
	send, e
	sleep, 750
	send, e
	sleep, 750
	click,  R
return

;keypad 7 - trap
Numpad7::
	Send, {f8}
	Sleep, 250
	send, 7
	Send, {f5}
return

;keypad 8 - tranq ammo
Numpad8::
	Send, {f7}
	Sleep, 250
	send, 1
	Send, {f5}
return

;keypad 9 - SOS
Numpad9::
	Send, {f8}
	Sleep, 250
	send, 3
	sleep, 250
	send, e
	send, 250
	Send, {f5}
return


;keypad Enter - heal pot
NumpadEnter::
	Send, {f8}
	Sleep, 250
	send, 6
	Send, {f5}
return

;get  ammo
NumpadDot::
	send, e
	sleep, 750
	click, 190, 129
	sleep, 750
	send, {f3}
	sleep, 750
	send, e
	sleep, 750
	send, e
	sleep, 750
	send, {esc}
	sleep, 750
	send, {esc}
	sleep, 750
	send, {esc}
return

;get  ammo  tent
NumpadMult::
	send, e
	sleep, 2500

	send, {Down}
	sleep, 500

	send, e
	sleep, 500

	send, e
	sleep, 500

	send, {f3}
	sleep, 500

	send, e
	sleep, 500

	send, e
	sleep, 500

	send, {esc}
	sleep, 500

	send, {esc}
	sleep, 500

	send, {esc}
	sleep, 500

	send, {esc}
return

;Make pierce Ammo 
NumpadSub::
	Send, {f6}
	Sleep, 250
	Loop 30
		if getKeyState("LShift", "P")
			send, +1
		else
			send, 1
	Send, {f5}
return

;Make sticking Ammo
NumpadAdd::
	Send, {f6}
	Sleep, 250
	Loop 30
		if getKeyState("LShift", "P")
			send, +2
		else
			send, 2
	Loop 9
		if getKeyState("LShift", "P")
			send, +3
		else
			send, 3
	Send, {f5}
return


;==============================Set and Forget Auto Clickers==========================
;Auto Clicker Routine (R KEY)
f1::
RepeatKey2 := !RepeatKey2

	If RepeatKey2 {
		SoundBeep
		SetTimer, SendTheKey2, 60
		}
	Else {
		SetTimer, SendTheKey2, Off
		SoundBeep
		SoundBeep
		}
	Return

SendTheKey2:
send, r
Return

;Auto Clicker Routine (E KEY)
end::
RepeatKey := !RepeatKey

	If RepeatKey {
		SoundBeep
		SetTimer, SendTheKey, 60
		}
	Else {
		SetTimer, SendTheKey, Off
		SoundBeep
		SoundBeep
		}
	Return

SendTheKey:
if getKeyState("LShift", "P")
send, +e
else
send, e
Return


;==============================Hold Auto Clickers==========================
;Auto Clicker Toggle
F4::
	if (autoclicker = 1) {
	autoclicker = 0
	SoundBeep
	SoundBeep
	}

	else {
	autoclicker = 1
	SoundBeep
	}
return

;Auto Clicker Routine (LEFT MOUSE)
$~lbutton::
	while ((getKeyState("lbutton", "P")) & (autoclicker = 1))
	{
		send, {lbutton}
		sleep, 1
	}
return

;Auto Clicker Routine (SPACE KEY)
$~Space::
	while ((getKeyState("Space", "P")) & (autoclicker = 1))
	{
		send, {Space}
		sleep, 1
	}
return


;enter jewel farm event
pgdn::
	;start
	send, e

	;post a new quest
	click, 200, 133
	sleep, 2000

	;events
	click, 613, 420
	sleep, 1000

	;the greatest jagras
	click, 293, 300
	sleep, 200


	;this will dissapear if u get a DC
	;multiplayer  options
	click, 433, 393
	sleep, 200


	;select camp
	click, 497, 303
	sleep, 200

	;accept
	click, 600, 323
	sleep, 6000

	;go
	send, {tab}
	sleep, 2000



	;multiplayer
	;goes  away  if  u  get  DC'ed
	send,  {space} 
	sleep,  200




	;accept
	send, e

return


;exit to headquarters
pgup::
	send, {esc}
	sleep, 300
	click, 170, 147
	sleep, 200
	click, 200, 236
	sleep, 200
	click, 583, 400
	sleep, 12250
	click, 1040, 373
	sleep, 200
	click, 1040, 278
	sleep, 2000
	click, 966, 273
	sleep, 200
	click, 576, 570
	sleep, 2000
	send, e
return




f11::
	Reload
	ExitApp
return
[Mod edit: [code][/code] tags added]
User avatar
Xtra
Posts: 1992
Joined: 02 Oct 2015, 12:15

Re: Need syntax help with break command

29 Oct 2019, 20:19

Try:

Code: Select all

f11::
Critical
Reload
ExitApp
return
Rioa
Posts: 5
Joined: 29 Oct 2019, 02:19

Re: Need syntax help with break command

30 Oct 2019, 02:25

didnt work either, also went a step further and changed f11 to 'p' key just to make sure it wasnt a reserved-key-problem during testing (and also move routine to beginning of script) -- still appends routine to bottom of call stack instead of breaking from the running stack. Other ideas? or should i start going with that clumsy pseudo-code solution
Sid4G
Posts: 49
Joined: 02 Apr 2016, 19:11

Re: Need syntax help with break command

30 Oct 2019, 13:33

You are doing clumsy pseudo code anyway so make a separate control script that restarts the process.
Rohwedder
Posts: 3625
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Need syntax help with break command

16 Nov 2019, 03:00

Hallo,
try:

Code: Select all

;+++++++++++++++++++++++++++++++
;enter jewel farm event
F11::pgdn := False
pgdn::
pgdn := True
Loop
{
                             ;new psuedocode -- I also dont know exact syntax 
                             ;Do While (f11 != pressed) ... Else (Break)
	;start
	send, e

	;post a new quest
	click, 200, 133
	sleep(2000,pgdn)
        ; ...
        ; ...
        ; ...
}
Return
;+++++++++++++++++++++++++++++++

Sleep(Time,ByRef On:=True)
{ ;like "Sleep, Time", but if On becomes Zero, the Thread ends
    End:= A_TickCount + Time
    While, S:= End-A_TickCount > 0
        IF On
            Sleep,S>100?100:S
        Else Exit
} ;a long Sleep will be segmented to be able to interrupt it fast


Return to “Gaming”

Who is online

Users browsing this forum: Google [Bot], Jumbled, PedroHenriq2200 and 16 guests