There are a couple of ways of doing this. I opened up my Inform to practice this and had your game file opened so I’m using examples from that.
The first is to make a table that just has one column (which I’ve called currentsound), and to pick a random row from it:
Table of random sounds
currentsound
sound of bookcheck
sound of addspellscroll
Instead of thinking:
Choose a random row from the table of random sounds;
play currentsound entry;
The second is to make a bigger table that categorizes the songs by their emotional content (which I’ve called ‘motif’ here). To pick a song with the right ‘motif’, you can sort the table randomly and then pick the first row with that motif:
A motif is a kind of value. The motifs are spooky, nice, and mean.
Table of sorted random sounds
currentmotif currentsound
nice sound of bookcheck
nice sound of addspellscroll
mean sound of playerdeath
Instead of sleeping:
sort the table of sorted random sounds in random order;
choose a row with currentmotif of nice in the table of sorted random sounds;
play currentsound entry;
You don’t have to use values or motifs, though, you could also do this with just rooms:
Table of sorted random sounds
currentroom currentsound
the clearing sound of bookcheck
the aether clearing sound of addspellscroll
the clearing sound of playerdeath
Instead of sleeping:
sort the table of sorted random sounds in random order;
let temp be the location of the player;
if temp is a currentroom listed in the table of sorted random sounds:
choose a row with currentroom of temp in the table of sorted random sounds;
play currentsound entry;
(note that, in case the code doesn’t copy right, there should be tabs between columns)
a little look at how i’ve used this to give a small audio prompt to set the tone of a line of dialogue (I’ve added enc to the name of some variables to allow for multiple characters using this method)