autohotkey can you help me? for if statement

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
99leeroi99
Posts: 18
Joined: 28 Oct 2021, 03:50

autohotkey can you help me? for if statement

28 Oct 2021, 03:53

hello I'm working something but I don't know how to do it I'm new at autohotkey script it's simple really but I don't know how to make it work

Code: Select all

loop{
SetTimer, Time, -2000
sleep, 10000
}
return
Time:
if (Time = 0){
        msgbox, hello
    }
else{
        msgbox, done
    }

return
    }
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: autohotkey can you help me? for if statement

28 Oct 2021, 05:31

AHK does not use variables in that way to track the timer's time, though code could be added to simulate that. In your script, the variable Time appears to be null at all times. You can prove that simply by displaying its value in the script. The problem can be fixed if you provide a description of what the script should do. In the meantime, this answer is already provided in your other post: viewtopic.php?f=76&t=96080

A loop, a sleep, and a timer are seldom needed together like this. If the purpose is to prevent the script from exiting, use #Persistent instead.

Labeled subroutines generally end in Return rather than a closing brace. Functions and other kinds of code blocks do use closing braces, but they also use opening braces. The bug in your script is easy to spot in two ways: first, your script contains an odd number of braces. Second, when you run the script, you receive an error message that provides both a description of the problem and the line number where it occurs.
99leeroi99
Posts: 18
Joined: 28 Oct 2021, 03:50

Re: autohotkey can you help me? for if statement

28 Oct 2021, 06:11

The script do work properly but I just don't know how to initiate the variable in this thing I'm just new
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: autohotkey can you help me? for if statement

28 Oct 2021, 06:29

My advice is to provide a description of exactly what this script should do, step by step. You know this, but the reader does not know this.

Setting a variable can be done like this.

Code: Select all

Time := 0
Explained: Variables

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: gongnl, Google [Bot], jaka1 and 254 guests