Page 1 of 1

Refresh Random after pressing a hotkey

Posted: 25 Mar 2023, 12:36
by MAZ12211
The only way for me to refresh randomTrack is via restarting the ahk file
But I want it to refresh after pressing CTRL + 3 for example
I tried refreshing it via loading up the ahk file after a hotkey but that didn't work...

Code: Select all

#SingleInstance Force
randomTrack := Random(1, 2)
isMuted := false
MsgBox "Controls:`nCTRL + 2 | Opens up the terminal`nCTRL + 3 | Loads a random song/track in tracks folder`nCTRL + 4 | Switchs to a mute song track"
^2::
{
    Run "wt.exe"
}

^3::
{
    SoundPlay "F:\Games\MAZ folder\Entries\tracks\track-" . randomTrack . ".mp3"
    ;loads track-1 or track-2 depending on randomTrack
}
^4::
{
    isMuted := True
    if isMuted = true {
        SoundPlay "F:\Games\MAZ folder\Entries\tracks\mute track.mp3"
    }
}

Re: Refresh Random after pressing a hotkey

Posted: 25 Mar 2023, 15:58
by mikeyww
Hello,

The Random function can be called inside your hotkey subroutine. This would mean that a new random number is generated whenever the hotkey is triggered.