Page 1 of 1

Stop a specific loop

Posted: 21 Feb 2018, 12:35
by Noo0B
Hello everyone,
I have a script with a loop that launches several subroutines, some with other subroutines with another loops inside, some launching other subroutines without loops.
I tried everything to stop the initial loop from launching them all at once.
I managed to stop the A_Index variable jumbling with a variable translation.
I tried to Use the Looping:= False command but it didn't work with all the loops inside the subroutines needing to run.
I could try a different loop for each subroutine but I guess I would still be with the same problem with different indexes launching the same subroutine instead of all types.
Is there a way to stop a specific loop then reactivate it?
Its all I need :)
Regards.

Re: Stop a specific loop

Posted: 21 Feb 2018, 12:48
by Noo0B
It can be only 1 type (subroutine) per loop index. I could try breaking the loop After the gosub, and adding the index and calling the loop again at the end of the last subroutine called by the initial subroutine for all types .

Re: Stop a specific loop  Topic is solved

Posted: 21 Feb 2018, 13:10
by stealzy
Use SetTimer instead.

Code: Select all

#Persistent
Global Stop_f_loop := false
SetTimer f, -1
Return

F1::Stop_f_loop := true

F2::
Stop_f_loop := false
SetTimer f, -1
Return

f() {
	static i := 0
	MsgBox % ++i
	If Not Stop_f_loop
		SetTimer f, -1
}

Re: Stop a specific loop

Posted: 21 Feb 2018, 14:59
by Noo0B
Thanks for the reply!
Although that was not exactly what I wanted I can see that you have great knowledge of AHK. I have no idea what ( ) does for example.
I actually got it fixed by doing the break after calling the sub and the index add at the end of the sub before recalling the loop.
Only problem is that an if statement fails to evaluate a variable at the end of the sub. For example:

Code: Select all

If (Var = W) {
Var2:= 123
Var3:= 456
} Else {
MsgBox %Var%
}
I keep getting the MsgBox with W...
It works well in another script
IsnĀ“t that something?
Thanks and Regards!