Tutorial: Manual Timer

July 11, 2006 |

Quest3D has it’s own way of creating timers, however sometimes you just want to create your own. Here I’ll describe a quick way of creating a timer using ExpressionValue channels.

[download source]

The ExpressionValue timer
First get yourself an ExpressionValue channel from the templates or channels pane, now open it and write (OLD + TC/25) into the textbox. Now link this channel to the start of your project and see what happens (it should count seconds now). Congratulations you’ve created a timer, so now what? Well there’s a few things a proper timer should really be able to do like pause, stop and start. Lets have a look at the code:

Timer

Here I use a value channel to hold the CurrentTime this channel is updated each frame (as you can see I’m using a setValue on top of all this logic). Now let’s start at the bottom, using the control variables I can now Start and Stop the timer, and the Pause variable will pause the timer. The expression used now looks like this:

(A + ( (TC/25) * !C ) ) * B

A is the current time, and each frame (TC/25) is added. As you can see I multiply this chunk with !C because C is the pause variable. Due to the inversion of C when this value is ‘1′ the timer will pause (’0′ is added to A each frame) and ‘0′ will unpause the timer.

To reset and stop the timer we need to set the current time to ‘0′ and prevent the timer to count. This is done using the Stop/Start value, as you can see, when this value is set to ‘0′ it will multilply the complete function with ‘0′ which it will do until this value is set back to ‘1′.

Now to add a bit more control to the timer I’ve added another ExpressionValue channel between the end result and the timer expression. The timer value will be passed through this expression as long as it’s value isn’t larger than End. If the timer is larger, then this expressionchannel will pass the Start value as the end result. So basically it says:

if CurrentTime greater then End then output Start else output CurrentTime

The advantage of this timer is that you can replace the CurrentTime value channel by an array value channel and call the whole tree in a For-Loop as often as you wish. But that’s for another post perhaps :)

Leave a Reply