Page 1 of 1

autohotkey can you help me? for if statement

Posted: 28 Oct 2021, 04:39
by 99leeroi99
hello I'm working something but I don't know how to do it I'm new at autohotkey script 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
    }
[Mod edit: [code][/code] tags added.]

I can't use the if statement the only thing that pop up is the done msg not the hello

Re: autohotkey can you help me? for if statement

Posted: 28 Oct 2021, 05:27
by just me
You did not initialize the variable Time. So it's empty and therefore not equal 0.

Re: autohotkey can you help me? for if statement

Posted: 28 Oct 2021, 06:10
by 99leeroi99
just me wrote:
28 Oct 2021, 05:27
You did not initialize the variable Time. So it's empty and therefore not equal 0.
sorry i'm new at this I don't know how to make it work :(

Re: autohotkey can you help me? for if statement

Posted: 28 Oct 2021, 06:16
by 99leeroi99
just me wrote:
28 Oct 2021, 05:27
You did not initialize the variable Time. So it's empty and therefore not equal 0.
can you help me to make this thing work?

Re: autohotkey can you help me? for if statement

Posted: 28 Oct 2021, 06:33
by just me

Code: Select all

; top of the script
time := 0 ; this initializes the variable time with 0 (zero)

loop{
	SetTimer, Time, -2000
	sleep, 10000
}
return
Time: ; <<<<< this is the label called Time, it's not the variable
if (Time = 0) { ; <<<<< this is the variable called time
	msgbox, hello
}
else {
	msgbox, done
}
return
}
But the value of the variable does not change automatically.

Re: autohotkey can you help me? for if statement

Posted: 28 Oct 2021, 06:40
by garry
also an example

Code: Select all

#persistent
time:=0
settimer,Label1,5000
gosub,Label1
return
;------------------
esc::
tooltip,QUIT this script %a_scriptname%
sleep,3000
tooltip
exitapp 
;-----------------
Label1:
if (time=0)
  msgbox, 262208, ZERO,Hello ,1   ;- show this the first-time , then see msgbox DONE each 5 second
else
  msgbox, 262208, DONE,Show this=`nEach 5 second ,1
time:=1
return
;=================================

Re: autohotkey can you help me? for if statement

Posted: 28 Oct 2021, 07:15
by 99leeroi99
garry wrote:
28 Oct 2021, 06:40
also an example

Code: Select all

#persistent
time:=0
settimer,Label1,5000
gosub,Label1
return
;------------------
esc::
tooltip,QUIT this script %a_scriptname%
sleep,3000
tooltip
exitapp 
;-----------------
Label1:
if (time=0)
  msgbox, 262208, ZERO,Hello ,1   ;- show this the first-time , then see msgbox DONE each 5 second
else
  msgbox, 262208, DONE,Show this=`nEach 5 second ,1
time:=1
return
;=================================

is there a way to loop this thing? like in your code the hello will show up in the first time then after 5 seconds it will show done msg then will go repeat it self to go hello

Re: autohotkey can you help me? for if statement

Posted: 28 Oct 2021, 07:44
by mikeyww

Code: Select all

#Persistent
SetTimer, Message, 2000
Message:
If firstMessage := !firstMessage
     MsgBox, 262208, DONE, Show this=`nEach 5 second, 1
Else MsgBox, 262208, ZERO, Hello, 1
Return

Re: autohotkey can you help me? for if statement

Posted: 28 Oct 2021, 07:49
by 99leeroi99
nvm I already fixed it thank you everyone :)

Re: autohotkey can you help me? for if statement

Posted: 28 Oct 2021, 09:03
by amateur+
mikeyww wrote:
28 Oct 2021, 07:44

Code: Select all

#Persistent
SetTimer, Message, 2000
Message:
If firstMessage := !firstMessage
     MsgBox, 262208, DONE, Show this=`nEach 5 second, 1
Else MsgBox, 262208, ZERO, Hello, 1
Return
This code sends Hello every 2nd time (4-seconds interval) too as sends Done. Is that what you wanted?