I am trying to make a script for working out (not really, just for practicing coding, but the idea for it came from exercises

Description of what this script does:
You press the START button. A round starts and a green progress bar shows the progress. If you don't press the REST button, the script will keep restarting the round. If you press the REST button, the script pauses the progress of the round, starts a rest timer with a red progress bar and after the rest time is up, continues running the round again.
The problem is that the rest button, despite being activated, won't work at all if you press it a second time in one round. It works the first time, but then, it doesn't react to clicking at all, I even added a tooltip to track whether the "Rest" label gets activate. However, when a new round starts, pressing the rest button works again. So basically it works only once per round.
Here is the code:
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
RoundDuration:=10
RestDuration:=5
RestTime:=0
PauseUsed:=false
Gui, New
Gui, Add, Progress, Hidden xp y10 h30 w1800 cRed BackgroundBlue vRestBar Range0-%RestDuration%, 0
Gui, Font, s90, Arial
Gui, Add, Button, vStartb gStart x50 y150 w600 h300, Start
Gui, Add, Progress, Hidden xp y+10 h30 w1800 cGreen BackgroundBlue vProgressBar Range0-%RoundDuration%, 0
Gui, Add, Button, Disabled vRestbutton gRest x50 y500 w600 h300, Rest
Gui, Show, Maximize Center
return
Start:
GUIControl, Hide, startb
GUIControl, Show, stopb
gosub RoundStart
return
RoundStart:
RestUsed:=false
SavedRoundTime:=0
GUIControl, Enable, restbutton
Roundtime:=0
gosub RoundTimer
gosub RoundStart
return
RoundTimer:
t1:=A_TickCount
GUIControl, Show, ProgressBar
While (RoundTime<RoundDuration+1) {
if (RestUsed) {
Roundtime:=SavedRoundTime+(A_TickCount-t1-RestTime)/1000
RoundTime:=Floor(RoundTime)
} else {
RoundTime:=(A_TickCount-t1-RestTime)/1000
RoundTime:=Floor(RoundTime)
}
GUIControl, ,ProgressBar, %RoundTime%
}
return
Rest:
tooltip, You pressed the Rest button
GUIControl, Disable, restbutton
RestUsed:=true
SavedRoundTime:=RoundTime
gosub RestTimer
GUIControl, Enable, restbutton
RestTime:=0
gosub RoundTimer
return
RestTimer:
t2:=A_TickCount
GUIControl, Show, RestBar
while (RestTime<RestDuration+1) {
RestTime:=(A_TickCount-t2)/1000
RestTime:=Floor(RestTime)
GUIControl, ,RestBar, %RestTime%
}
GUIControl, Hide, RestBar
Return
Esc::
ExitApp
Please help me understand how to fix this. I would be really thankful
