Need help for my script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Yaruqii
Posts: 32
Joined: 11 Jul 2021, 16:29

Need help for my script

Post by Yaruqii » 24 Jan 2023, 16:22

This is the script I have, but its not working as wanted, could you edit my script, so that is working as I will explain later on?

Code: Select all

 Gui, Add, Text, x20 y20 w100 h20, First Launch
Gui, Add, Text, x20 y80 w100 h20, % "Countdown: 21.5"
Gui, Add, Text, x20 y50 w100 h20, Second Launch
Gui, Add, Text, x20 y110 w100 h20, % "Countdown: 7"
Gui, Show

End::
SoundBeep, 1500
countdown1 = 21.5
countdown2 = 7

Loop {
    countdown1 -= 0.1
    countdown2 -= 0.1
    GuiControl, , Countdown1, % countdown1
    GuiControl, , Countdown2, % countdown2
    if (countdown1 <= 0) {
        SoundBeep, 1000
        break
    }
    Sleep, 100
}

Loop {
    countdown2 -= 0.1
    GuiControl, , Countdown2, % countdown2
    if (countdown2 <= 0) {
        SoundBeep, 500
        break
    }
    Sleep, 100
}
So the script in the end should do the following:
I have a script which is beeping when I press End on my keyboard, then its counting down 21.5 seconds and beeps another time thats should be the „first launch“. Then after this beep, it shoult count down 7. seconds, after the 7 seconds it should beep a last time. So these countdown I want to display in a gui, which I also tried to do. It should look like this

Before pressing end:

First Launch:
Press END to start
Second Launch:
Press END to start

When pressed END:

First Launch:
Time: 21.5s <-(this timers updating every 0.1 seconds)
Second Launch:
Wait…

When Second Countdown started:

First Launch:
Fired…
Second Launch:
Time: 7.0s

After every countdown is done, the gui should reset to the Before pressing END state.
I would also like you to do a thin outline around the first and second countdown if possible.
And please add the AlwaysToTop function, so that this windows is always on top of other Windows.

Thanks for helping me! Really appreciate it! :D

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: Need help for my script

Post by DuckingQuack » 26 Jan 2023, 21:32

This was a challenging little project for me that let me learn about SetTimer and that the Help Docs are terrible.

I'd celebrate anyone who can point me to the page that says guictrl.control means MyGui["TextBoxName"].text

But aside from that dilemma and having to scrap the code three times because I'm either too inexperienced to know how to do it those ways or I'm too inexperienced to know it can't be done that way!
I'm still very new to coding in general and there is probably a better/easier/efficient way to do this, but after two days of struggling, I managed to build something that at least accomplished the goal!

:roll: This was written with VERSION TWO, so you'll have to upgrade if you decide to try this one out. :?

Code: Select all

#Requires AutoHotkey v2.0

Esc:: ExitApp

HUD := Gui("+AlwaysOnTop -Caption +ToolWindow", "Launch HUD")
HUD.BackColor := "Teal"
HUD.SetFont("s20 cWhite")
HUD.Add("Text", "w300 Center", "Launch HUD")
HUD.SetFont("s12")
HUD.Add("Text", "xm w150 Center Section", 'First Launch')
HUD.Add("Text", "ys w150 Center", 'Second Launch')
HUD.Add("Text", "xm w150 Center Section vFirstClock", "Press END to start")
HUD.Add("Text", "ys x+30 w150 Center vSecondClock", "Press END to start")
HUD.Show("NoActivate")


End:: {
    SoundBeep(, 1500)

    SetTimer(Countdown1, 100)
    Countdown1() {
        Static Var1 := 21.5
        HUD['FirstClock'].Text := Round(Var1, 1)
        HUD['SecondClock'].Text := "Waiting..."
        if (Var1 < 0.1 && Var1 > -0.9) {
            SetTimer(, 0)
            SoundBeep(, 1000)
            HUD['FirstClock'].Text := "Fired..."
            Var1 := 21.5
            SetTimer(Countdown2, 100)
        }
        Var1 -= 0.1
    }
    Countdown2() {
        Static Var2 := 5
        HUD['SecondClock'].Text := Round(Var2, 1)
        if (Var2 < 0.1 && Var2 > -0.9) {
            SetTimer(, 0)
            SoundBeep(, 500)
            HUD['FirstClock'].Text := "Press END to start"
            HUD['SecondClock'].Text := "Press END to start"
            Var2 := 7
        }
        Var2 -= 0.1
    }
}
Best of Luck,
The Duck

NewberEnerNeeder1
Posts: 47
Joined: 26 Mar 2019, 06:06

Re: Need help for my script

Post by NewberEnerNeeder1 » 26 Jan 2023, 22:09

this might work or might not...not tested

Code: Select all

Gui, Add, Text, x20 y20 w100 h20, First Launch
Gui, Add, Text, x20 y50 w100 h20, Countdown: 21.5
Gui, Add, Text, x20 y80 w100 h20, Second Launch
Gui, Add, Text, x20 y110 w100 h20, Countdown: 7
Gui, Show

countdown1 := 21.5
countdown2 := 7

Loop {
    countdown1 -= 0.1
    GuiControl,, Countdown1, % countdown1
    if (countdown1 <= 0) {
        SoundBeep, 1000
        break
    }
    Sleep, 100
}

Loop {
    countdown2 -= 0.1
    GuiControl,, Countdown2, % countdown2
    if (countdown2 <= 0) {
        SoundBeep, 500
        break
    }
    Sleep, 100
}

Post Reply

Return to “Ask for Help (v1)”