Introduction to Time / Timer functions

6

Index

Attached Files

The following files have been attached to this tutorial:

.capx

Stats

10,958 visits, 22,819 views

Tools

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 15 Oct, 2013. Last updated 19 Feb, 2019

Start / Stop / Continue

To make things faster, we'll clone the SSR button and text in the layout. Use the right mouse above an object and select "Clone object type". This will make completely new objects and not a new instance of these objects.

Change button and text object names from "SSR2" to "SSC".

Rename the button text to "Start/Stop/Cont."

Add to the button a new instance variable called "memorize_me"

In the Event sheet, add the global variable Timer_SSC.

You can copy the whole Button SSR code and duplicate it via copy and paste (in order to select the whole code, click on the green arrow at the left of the event).

One has to click on each an every event and action to change it accordingly from SSR to SSC!

Do the same with the sub-event in "Every tick". Copy it and paste it and rename SSR to SSC accordingly.

Your event code window should now look like this:

Test first, before continuing

Click on the buttons to see if both are reacting similarly. When that is fine, we need to implement the memorize_me variable.

Take a look at this chart to understand what is happening:

The time starts running from 0 when the game starts.

As soon as button SSR is triggered, time is saved in the variable. The difference to time is the new counter! At second 9, we press the button and counter stops. When we press again on second 14, it all starts over again. time (14) - Timer_SSR (14) = 0

With the button SSC, we want to achieve something different. When we stop at second 9, the variable memorize_me gets the time difference, which can then be passed on at second 14. Now the counter can continue from 6 on.

Note: You might notice that the maths are right in the excel screenshot. But the counter will not stay on seconds 6 for twice the time! Why? Because the button is not triggered at exactly that time! Instead it might be at 5.2 or 5.8. And it will continue counting from that point on.

We can leave the Every tick events as they are. The only modification is done where we need to save the triggered value to memorize_me and when the timer needs to restart, where we also insert the memorize_me value. Here's the code:

  • 0 Comments

Want to leave a comment? Login or Register an account!