Tuesday, 17 February 2015

TS2015 - Scenario Scripting in LUA Part 11 - Audio

Audio is a really great way to kick your scenarios up a notch, you could use it to play some instructions for the user or to have scenario specific audio playing such as station announcements or other such things.  It's up to you to record the audio though of course!

In LUA, managing Audio is done through three commands:

SysCall("ScenarioManager:PlayDialogueSound", "test.wav")

SysCall("ScenarioManager:StopDialogSound", "test.wav")

SysCall("ScenarioManager:IsDialogSoundPlaying", "test.wav")

PlayDialogSound will begin playing the audio, it returns immediately so your script can continue doing things while the audio is playing.

This is great because it means you can get on and do other things, let the player carry on driving and so forth however if you want to play something straight afterwards, or if you want to play something new then it's good to know if something is already still playing.

IsDialogSoundPlaying will return "TRUE" if the audio is playing, and then you can issue a StopDialogSound to stop it playing.

You must always stop an audio file playing before you start another one, or the new one is simply ignored.

You can use this in a number of ways - when you arrive at a station perhaps an audio file plays something that has had suitable echo applied which sounds like a station announcement.  You could even work out how late the player is and play "sorry for the late arrival of this train" if late, or "the on-time service on platform 2..." if they're reasonably on time.

Using the functions you can even chain things together to be a little more dynamic, for example, let's say that you want to read out the current speed at some point - you would work out what files you're going to play, e.g. "fifty.wav" and "six.wav", then you would play the first one, use a condition to wait for it to finish (ie. the condition would keep calling IsDialogSoundPlaying(fifty.wav)  ) - and then kick off "six.wav" afterwards.  That way you can end up with some that says "you went through the checkpoint at... fifty...six...miles per hour".  This is basically the same way that telephone systems read out things like "you have...fifty...six... new voice mails".

So, where do you place the files?

Remember back when I covered where you place HTML files?  It's exactly the same.  They go in a localised folder name, so english sound files go in an "En" folder, that way the right sounds will be played depending on the preferred language of the person playing the scenario!

It's simple, it's easy to use, and you can use it to great effect in your scenarios!


  1. Can i trigger this command on distance, before the train is arrival on a platform?
    Example: 1000 metres before the platform, that a file is playing that says wich stop there is.

  2. StopDialogueSound

  3. I am trying to get rain sounds when it is raining, but they wont load. the rain is timed, and not on a track marker. please help as it is the only thing left to do on a scenario.