Way to compress if statement?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ry3ks3u_m4dd0ns
Posts: 18
Joined: 29 Mar 2017, 09:23

Way to compress if statement?

01 Apr 2017, 19:21

What I'm trying to do is:

Loop a certain action, and before every loop, to add 1 to a variable.
At the end of the loop, it checks if the variable is at the multiples of 10 (10,20,30,40 etc.), and if it is, to throw a Gui asking if the user wants to continue.
And if the user clicks Continue, the script goes on until it hits another multiple of 10.

So far, this is what I have:

Code: Select all

#CommentFlag //
Loop 
{
	shitvar += 1
	Sleep, 1000 //Not the action I actually want to do, but eh.
	If shitvar = 10
	{
		Gui, destroy
		Gui, Add, Text, x10 y5, You've been useless for %shitvar% times.
		Gui, Add, Text, x10 y20, Do you want to continue?
		Gui, Add, Button, x10 y50, Stop
		Gui, Add, Button, x50 y50, Continue
	}
}
The Gui part is easy for me, but it seems like I can't do this without flooding the script with multiple IF statements.

Is there a way to compress the IF statement?
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Way to compress if statement?

01 Apr 2017, 19:29

What you want is the Mod() function. Mod(shitvar,10) will be zero if it's a multiple of 10. So If !Mod(shitvar,10) is the if statement you want.

Alternatively, and this is what you can use if you have an irregular pattern (like 1, 4, 7, 9, 15, 22) is using the OR operator If (shitvar=1) || (shitvar=4) || (shitvar=7) || (shitvar=9) || (shitvar=15) || (shitvar=22).

But that's long-winded. An alternative to that alternative is you can use If var in to see if it's in a list. If shitvar in 1,4,7,9,15,22
ry3ks3u_m4dd0ns
Posts: 18
Joined: 29 Mar 2017, 09:23

Re: Way to compress if statement?

01 Apr 2017, 19:37

Exaskryz wrote:What you want is the Mod() function. Mod(shitvar,10) will be zero if it's a multiple of 10. So If !Mod(shitvar,10) is the if statement you want.

Alternatively, and this is what you can use if you have an irregular pattern (like 1, 4, 7, 9, 15, 22) is using the OR operator If (shitvar=1) || (shitvar=4) || (shitvar=7) || (shitvar=9) || (shitvar=15) || (shitvar=22).

But that's long-winded. An alternative to that alternative is you can use If var in to see if it's in a list. If shitvar in 1,4,7,9,15,22
When I saw 'alternative to that alternative' I was -mind has been blown-

But, on a serious note, thank you. I'll try these options and reply back on progress.
ry3ks3u_m4dd0ns
Posts: 18
Joined: 29 Mar 2017, 09:23

Re: Way to compress if statement?

02 Apr 2017, 08:18

Long story shot, all options worked.

The reply was delayed because power went off. For an entire night.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], madensuyu1, peter_ahk and 360 guests