Following on from the series begun earlier, this post talks about how you can allow your users to recall pop-up messages easily.
If you’re providing any kind of instruction to the player then you should definitely use the Recorded Message capability of the scripting system to handle that pop-up message box so that the player can bring it back on-screen to remind themselves what they need to do.
Let’s write a quick function to simplify showing these messages, this will allow us to use a more simple command later when we want to actually show them, as well as enforce a degree of consistency on our code later on.
function DisplayRecordedMessage( messageName ) SysCall("RegisterRecordedMessage", "StartDisplay" .. messageName, "StopDisplay" .. messageName, 1); end
The way that the Recorded Message capability works is that you tell it a function name to execute when it shows message and another function to execute when it hides the message. In the case of simply showing a simple or HTML message you generally won’t have anything in the “stop” function. Where things get potentially complex and powerful is when you realise you can put any code in those functions, so you can trigger cameras, audio playback and so forth. As an example, if you use the “Start” function to trigger a cinematic camera then the “Stop” function probably should put it back to the cab view.
Let’s define those two functions now for a simple HTML pop-up:
function StartDisplayIntroText() SysCall ( "ScenarioManager:ShowInfoMessageExt", "Title of the box", "introtext.html", 0, MSG_VCENTRE + MSG_CENTRE, MSG_REG, TRUE ); end function StopDisplayIntroText() end
So, why did we call the functions “StartDisplayIntroText” and “StopDisplayIntroText” ? Let’s actually write some code to call “DisplayRecordedMessage” and that will complete the picture.
function OnEventStart() DisplayRecordedMessage("IntroText") end
Again, this is done using our previously described mechanism of having each event in its own function.
You can see that when we call DisplayRecordedMessage we are passing in the parameter “IntroText”, the DisplayRecordedMessage function will then find the two functions that begin “StartDisplay” and “StopDisplay” that have this in them – so StartDisplayIntroText and StopDisplayIntroText, and register them with the game to show a recorded message.
When you call DisplayRecordedMessage the game will immediately call the StartDisplay function and when the player closes the message box, the game will call the StopDisplay function.
That’s it for todays post – tomorrow I will talk about Cinematic Cameras as well as how you can call up the standard cameras from script such as the Cab Camera.