0
votes

I'm trying to get an if statement inside a loop of ahk to run some code ONLY after the counter variable value is greater or equal to X(lets use 10 for this example), if the condition is met, it sends some words to a text input, then reset the counter variable to 0 again. so I'm using IfGreaterOrEqual but it just bypasses it.

its not working, it keeps going through as nothing. could some one shed some light into what am I doing wrong?

F3::
Toggle := !Toggle
if(Toggle){
    gosub Loop1
    gosub Loop2
}
SetTimer, Loop1, % (Toggle) ? 19550 : "Off"
SetTimer, Loop2, % (Toggle) ? 306500 : "Off"
return

F4::Reload

Loop1:
vCOUNT++
SendInput word-1{Enter}
IfGreaterOrEqual, vCOUNT, 10
SendInput word-2{Enter}
SendInput word-3{Enter}
vCOUNT :=0
SendInput Counter was reset, its value is now: %vCOUNT% {Enter}
return

Loop2:
SendInput word-4{Enter}
SendInput word-5{Enter}
SendInput word-6{Enter}
SendInput word-7{Enter}
return
1

1 Answers

1
votes

I don't know if i get your problem right but I think your problem is that in Loop1, the condition is ignored and even in the first iteration it will set vCOUNT back to zero.

So the problem with this is that you can see that it somehow not ignores the "IfGreaterOrEqual" because "SendInput word-2{Enter}" is not executed. So the statement only affects the next line but you want it to affect a complete block. To solve this, you have to put brackets around the codeblock you want. In your "Loop1" example (if i get your idea right), it should look like that:

Loop1:
    vCOUNT++
    SendInput word-1{Enter}
    IfGreaterOrEqual, vCOUNT, 10
    {
        SendInput word-2{Enter}
        SendInput word-3{Enter}
        vCOUNT :=0
        SendInput Counter was reset, its value is now: %vCOUNT% {Enter}
    }
return