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, 04:39

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
just me
Posts: 9459
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: autohotkey can you help me? for if statement

28 Oct 2021, 05:27

You did not initialize the variable Time. So it's empty and therefore not equal 0.
99leeroi99
Posts: 18
Joined: 28 Oct 2021, 03:50

Re: autohotkey can you help me? for if statement

28 Oct 2021, 06:10

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 :(
Last edited by 99leeroi99 on 28 Oct 2021, 06:20, edited 1 time in total.
99leeroi99
Posts: 18
Joined: 28 Oct 2021, 03:50

Re: autohotkey can you help me? for if statement

28 Oct 2021, 06:16

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?
just me
Posts: 9459
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: autohotkey can you help me? for if statement

28 Oct 2021, 06:33

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.
garry
Posts: 3770
Joined: 22 Dec 2013, 12:50

Re: autohotkey can you help me? for if statement

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
;=================================
99leeroi99
Posts: 18
Joined: 28 Oct 2021, 03:50

Re: autohotkey can you help me? for if statement

28 Oct 2021, 07:15

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
User avatar
mikeyww
Posts: 26947
Joined: 09 Sep 2014, 18:38

Re: autohotkey can you help me? for if statement

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
99leeroi99
Posts: 18
Joined: 28 Oct 2021, 03:50

Re: autohotkey can you help me? for if statement

28 Oct 2021, 07:49

nvm I already fixed it thank you everyone :)
amateur+
Posts: 655
Joined: 09 Oct 2021, 15:43

Re: autohotkey can you help me? for if statement

28 Oct 2021, 09:03

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?
Have found any drawback in my code or approach? Please, point it out. /The moderator ordered to remove the rest of the signature, I had obeyed.
And I really apologize for our russian president. Being a citizen of an aggressor country is very shameful. Personally I tried to avoid this trying to defend elections from fraud being a member of the election commission of one of the precincts but only was subjected to a hooligan attack and right before the vote count was illegally escorted from the polling station and spent the night behind bars (in jail) in a result of illegal actions of corrupt policemen.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: digidings, Ineedhelplz, mikeyww and 201 guests