Set up a 88:88 Type Timer

Created by Arty
Copied from Wayback Machine

Here is some kode for a basic countdown clock that I put in one of my levels

1. when [duration timer][GameLengthInSecs] do
2.    when do [Minutes][=][floor][(][timer seconds remaining][divide by][60][)]
3.    when do [Seconds][=][floor][(][timer seconds remaining][modulo][60][)]
4.    when [Seconds][<][10] do [display][screen top right][Minutes][+][:][+][0][+][Seconds][x-large]
5.       when [else] do [display][screen top right][Minutes][+][:][+][Seconds][x-large]

6. When [countdown timer][GamelengthInSec] do [switch page][Game Over]

key: [blue] = user defined variable    [red] = values defined

Fairly straight forward. It uses a duration timer to control the length of the countdown on screen and uses [timer seconds remaining] to calculate timers display values. [timer seconds remaining] is a value only available within a timers scope and is found in [output] folder.
The actual display is slightly complicated by that fact the PS default display on screen does not have leading zeroes. e.g 1 minute and 9 secs without the zero looks like 1:9 and that just looks wierd, we want 1:09. So on line 4 for values less than 10 you display the zero explicitly.

NB the reason that the countdown is not to control the on screen timer is because it only executes the once! So I needed both a duration and countdown.

To make this into a timer going up in value you could just replace [timer seconds remaining] with [time seconds completed], but this has restrictions in that the timer will eventually end, I have not tested putting huge number in duration but that may work 

To make an open ended timer will require slight restructuring.

1. when [once] do [GamelengthInSec][=][0]
2. when [countdown timer][1][loop] do [GamelengthInSec][increment by][1]
3.    when do [Minutes][=][floor][(][GamelengthInSec][divide by][60][)]
4.    when do [Seconds][=][floor][(][GamelengthInSec][modulo][60][)]
5. when [Seconds][<][10] do [display][screen top right][Minutes][+][:][+][0][+][Seconds][x-large]
6.    when [else] do [display][screen top right][Minutes][+][:][+][Seconds][x-large]

key: [blue] = user defined variable    [red] = values defined

with no fixed duration its necessary to count the passing of time, line 1 and 2 set up a variable holding the number of seconds elapsed and incrementing it by 1 every time the countdown timer triggers, it is defined to trigger once every second.
NB this too can be used to do countdowns i.e. change line 1 to set countdown duration and change line 2 to decrement the value.

As said before, there is always more than one solution to a programming task.

I’ll let the displaying of durations in hours be something for the future 



Comments are closed.

Website Powered by

Up ↑

%d bloggers like this: