Playsound with variable that contains path, sound file and Volume control?

I have a database where I want to play certain songs. Here’s how I’ve been doing it with one permanent variable and some file global variables.

pvMyPath = "/Users/Larry/Music/iTunes/ShortSongs/"
fgTheSong =  "ShortTheGambler.m4a" 
fgTheSongToPlay = pvMyPath + fgTheSong
playsound fgTheSongToPlay

That has been working great. But now I want to make sure that when the song is played, it doesn’t blast out too loud. For a song I name in the code, the following line works.

playsound "/Users/Larry/Music/iTunes/ShortSongs/ShortTheGambler.m4a","VOLUME",0.5

I tried putting the above line in a variable, by building the variable by adding the parts together -

pvMyPath = """/Users/Larry/Music/iTunes/ShortSongs/"
fgTheSong = "ShortTheGambler.m4a" + {"}
fgThePathSongVolume = pvMyPath + fgTheSong + "," + {"VOLUME"} + "," + "0.5"

Which gives the content of the variable - “/Users/Larry/Music/iTunes/ShortSongs/ShortTheGambler.m4a”,“VOLUME”,0.5

When I output the variable with a message statement, it looks correct—exactly like the path, song, volume that works when it’s not in a variable. But when I put this variable after the playsound statement,

playsound fgThePathSongVolume

I get the error:

Cannot play sound (“/Users/Larry/Music/iTunes/ShortSongs/ShortTheGambler.m4a”,“VOLUME”,0.5).

Can the volume option be used in or with a variable? What am I doing wrong? Any help would be appreciated.

You have 3 parameters there. Then you are putting them all into one variable, and using the variable as the first and only parameter. If you always want the same volume, you could just change your first version to this.

pvMyPath = "/Users/Larry/Music/iTunes/ShortSongs/"
fgTheSong =  "ShortTheGambler.m4a" 
fgTheSongToPlay = pvMyPath + fgTheSong
playsound fgTheSongToPlay, "VOLUME", 0.5

Dave, that does exactly what I want. Perfect! Thank you!

And thank you for your explanation of parameters. I love how Panorama uses parameters, and I often make use of them. But sometimes, since parameters are often optional, like with playsound, I get in the mindset that I don’t need them, even when that’s exactly when I do.