Tuesday 10 February 2015

TS2015 - Scenario Scripting in LUA Part 8 - Locking and Unlocking Controls

We've covered some interesting examples in previous articles where you can take control of the player train, perhaps to bring it to stop if the player breaks some speed limit too much.

One of the weaknesses in those examples is that currently they are one-shot, once the script has changed the controls to stop the train, it sits back and relaxes, so the player can just as easily jump in and reset them to keep going again if they want to.

Some times we want to be a little more insistant.  There are a couple of ways of doing it and some are more appropriate for different situations than others.

You could use all that you've learned so far to simply keep continually resetting a control to some stored value, that way no matter what the player does with it, it will be forced back to the same place again.  This has the effect of preventing its movement, but doesn't look great in the UI because the control appears to move and then keep springing back.

Another approach is to ask the game to lock out the controls, the LUA script command to do this is:

SysCall ( "ScenarioManager:LockControls");

You can (and must, at some point!) then unlock them using this control:

SysCall ( "ScenarioManager:UnlockControls");

When you issue the "LockControls" command it will remove any HUD and prevent all keyboard inputs, it will be impossible to move any controls at all!

There is a downside to this... once you have locked out the controls, the player cannot pause the game or exit it.  So if you use it, then please make sure you use it sparingly and appropriately, and always remember to unlock it again!

A short post today, more tomorrow!




No comments:

Post a Comment