Loading a random sound file via Random() Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
MAZ12211
Posts: 2
Joined: 20 Mar 2023, 16:33
Contact:

Loading a random sound file via Random()

Post by MAZ12211 » 20 Mar 2023, 17:04

Trying to load a sound file via soundPlay with Random
But I got this error
I'm still a beginner at this, so I'm sorry if the code is written weirdly

Code: Select all

Error: Unexpected operator following literal string.

Specifically: + randomTrack + ".mp3")

	008: }
	011: {
▶	012: SoundPlay("F:\Games\MAZ folder\Entries\tracks\track-" + randomTrack + ".mp3")
	013: }
	015: {

Code: Select all

randomTrack := Random(1, 3)
isPaused := false
MsgBox "Hello, world!"
^2::
{
    Run "wt.exe"
}

^3::
{
    SoundPlay "F:\Games\MAZ folder\Entries\tracks\track-" + randomTrack + ".mp3"
    ; Load a random song/track as track-1.mp3, track-2.mp3 depending on randomTrack
}
^4::
{
    isPaused := true
    if isPaused = true {
        SoundPlay "F:\Games\MAZ folder\Entries\tracks\mute track.mp3"
        ;if pressed CTRL + 4 it'll load a mute track/song to "pause" the songs running
    }
}

User avatar
mikeyww
Posts: 26951
Joined: 09 Sep 2014, 18:38

Re: Loading a random sound file via Random()  Topic is solved

Post by mikeyww » 20 Mar 2023, 19:07

Welcome to this AutoHotkey forum!

The + is a mathematical operator in AHK. You can concatenate strings with .. In most situations, the dot can optionally be omitted.

Explained: Concatenate

Post Reply

Return to “Ask for Help (v2)”