Timers

From WiCWiki

Revision as of 11:28, 11 December 2007 by kowalski (Talk | contribs)
(diff) ←Older revision | Current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Contents

About timers

Timers in WIC are very useful tools. You can use it in primary or secondary objectives as a fail condition or just trigger special events.

A Timer in WIC is a visible countdown timer shown in top of the screen. If you don’t want to show the countdown a delay could be used instead.

But in this section only countdown Timers will be explained.


Creating a timer

Now we will go ahead and create a timer. First we will explain the different parts of the function, which looks like follows:


Timer( aTime, someActions, aTimerText, aAutoStart, aTimerIndex )


aTime is the time in seconds, used for the countdown.

someActions is a single Action or a list of Actions performed when the countdown is finished.

aTimerText is the Text shown in front of the countdown time on screen. It is good to have a pretty explaining text here.

aAutoStart is a Boolean value that sets if the timer will start directly after creation or if it should wait for a trigger.

aTimerIndex is used if a second timer should be shown on screen at the same time. 0 will set the timer to be shown centered on the screen and 1 will set the timer to be shown on the right.


Let´s start with creating a variable in mapvars.py. This will make the timer savable/loadable when you save/load your game.

myFirstTimer = None

While we still are in mapvars.py we can add a variable for the aTime value. This has no vital importance, but makes it easy to access if you need to change it later on.

Set it to one minute or to be exact, 60 seconds.

TheTime = 60

With this done lets us continue to the server.py file.

Now before writing the function I have chosen to trigger a messagebox when the timer has counted down. The one made in the messagebox chapter will do. I also chose to name aTimerText to ‘My First Timer’. The function should now look like this.

mapvars.myFirstTimer = Timer( mapvars.TheTime, Action( ShowMessageBox, 'Test_1', 1 ), ‘My First Timer’,  aAutoStart, aTimerIndex )

So far so good.

To make it easy this first time of Timer handling the aAutoStart can be set to True, so we don’t need to trigger the start. aTimerIndex is not really necessary now since we will not have a second timer showing at the same time. But for the correctness of the functions I will put it there anyway. The function should now look like this.

mapvars.myFirstTimer = Timer( mapvars.TheTime, Action( ShowMessageBox, 'Test_1', 1 ), ‘My First Timer’,  True, 0 )


Now to test it. When the game starts it should look something like this.


Image:Scripted_timer_001.jpg


Timer methods

Now you can make basic timers and have them trigger events at countdown.

But there is more to timers than this. I will explain some useful methods that can be used with timers.


IsActive()

This will return True if the timer is active. ex.

if mapvars.myFirstTimer.IsActive( ):
    ShowMessageBox( ‘Test_1’, 1 )


Start()

This is used to start the timer if aAutoStart is set to false. This gives you a better control over the timer start.

ex.

mapvars.myFirstTimer.Start()

Pause()

This is used to pause a timer.

ex.

mapvars.myFirstTimer.Pause()


Resume()

This is used to unpause a timer.

ex.

mapvars.myFirstTimer.Resume()

Remove()

This is used to permanently remove a timer.

ex.

mapvars.myFirstTimer.Remove()

AddTime( aTimeToAdd )

This is used to add time to a timer.

ex.

#this will add a minute to the timer
mapvars.myFirstTimer.AddTime( 60  )  

RemoveTime( aTimeToRemove )

This is used to remove time from a timer.

ex.

#this will remove ten seconds from the timer
mapvars.myFirstTimer.RemoveTime( 10  )  

GetTimeLeft()

This will return the time left in a timer. ex.

if mapvars.myFirstTimer.GetTimeLeft() <= 10:
    ShowMessageBox( ‘Test_1’, 1 )

AddActionAfterStart( aTimeAfterStart, aAction )

This will add an Action x seconds after the timer start.

ex.

mapvar.myFirstTimer.AddActionAfterStart( 10, Action( ShowMessageBox, ‘Test_1’, 1 ) )

The example above will show a messagebox 10 seconds after timer start.


AddActionBeforeEnd( aTimeBeforeEnd, aAction )

This will add an Action x seconds before the timer end.

ex.

mapvar.myFirstTimer.AddActionBeforeEnd( 20, Action( ShowMessageBox, ‘Test_1’, 1 ) )

The example above will show a messagebox 20 seconds before the timer ends.

Tick Tack

The powerful tool that is timers have now been presented for you. How you choose to use it is up to you, but here are some useful tips when dealing with timers.

Stress element.

A ticking timer can make an otherwise trivial task interesting. The fight against time will be as important as the ones against the enemies. But be careful when setting the time so that it isn’t to short. The excitement can be turned to frustration if the task seems overwhelming and unachievable.

So when you playtest the map, take a note of the time it takes for you to finish the task. There should be plenty of time left when you are done with the task. If you barely make it will be way too hard and you should add more time to the timer.


Less is more.

When designing your map try not to overuse timers. Forcing the player to fight against timer after timer will make you lose the wanted stress element. Maybe even push the players into frustration.

Also try to avoid multiple timers at the same time. Double the timers do not equal double the fun. It can be effective, but the risk is that the player will have problems keeping track of them both.


Time not important. Only life important. - Mondoshawan: The Fifth Element


Chapter 15: Objective Cameras < > Chapter 17: AI setup and usage
Personal tools
User Created Content