I trying to play the sound effect of a door opening on a page but when I go back to the page the sound effects plays again.Does anyone know the code for a sound to play once instead of just autoplay?
Please let us know what system you’re using, such as Twine and the version.
On my assumption that it’s a choice narrative system (based on your mention of pages), you need to set a variable or check how many times the passage has been “visited”. This code will vary based on what system you are using.
I can show you pseudocode based on AXMA (which is very close to Twine 1 or potentially Sugarcube?) and may not work directly but this is how you set it up.
If you have a macro to check passage visit count:
:: dooropen <<if visited ('dooropen') = 1>> <<[play sound 'doorcreak.mp3']>> You open the door and it creaks ominously! <<else>> The door is already open. <<endif>>
Or with a variable:
:: Open the Door <<if $dooropen neq true>> <<[play sound 'doorcreak.mp3']>> You open the door and it creaks ominously! <<set $dooropen = true>> <<else>> The door is already open. <<endif>>
Alternately, you can check if the passage to open the door has been visited (via macro or variable) and just hide the link to the passage that plays the sound again if they’ve already done it.