Set up a timer without using If statements

Learn how to make certain types of games and use gameEditor.

Set up a timer without using If statements

Postby Hblade » Sat May 05, 2012 10:18 pm

Hi! This tutorial will show you how to make a CountDown Timer using no if statements what-so-ever :D

ASSUMING YOUR FRAME RATE IS 30

First, create a text actor. Now open Global Code and type the following:
Code: Select all
int fm, time[3];


Now in CreateActor of the Text Actor, lets place this code:
Code: Select all
fm=3600;

At the moment, this is 2 minutes. Use a calculator to determine how long you want, by doing this kind of method

CALCULATOR:
60*60*60, seconds, minutes, hours. 60*60 is 3600, you have 2 60's, meaning its equal up to 2 minutes, because 60 seconds is 1 minute. If you want more than that, you'd type this in a calculator:
Code: Select all
60*60*5

This equals 18000, meaning 5 minutes. if you want an hour, you'd type 60*60*60, and if you want say... 5 hours, you'd type 60*60*60*5 :) which means 1080000 frames. IF you want to use SECONDS, then you'd do this: 30*seconds, for example: 30*12 which is 360 frames, which means 12 seconds.

Finally, go to draw actor and read through this commented code
Code: Select all
xscreen=0;
yscreen=0;

//if the frame is greater than or equal to 1, frame is subtracted by 1
fm>=1 && fm--;

// set up where seconds mniutes and hours add up and reset.
//Seconds:

time[0]=fm/30-(time[1]*60); //if frame is set to 30, add by 1, and if minut is 1, reset to 0;

//Minutes:
time[1]=fm/(30*60)-(time[2]*60); //if 60 seconds, add minute by 1, if hour incraeses, reset minutes to 0

//Hours
time[2]=fm/(30*(60*60)); //add an hour when 60 minutes have been added.

//Place the text:
sprintf(text, "%d : %d : %d", time[0], time[1], time[2]);

//when time is ran up, use a script, in this case,
//type Time Up on the screen.
fm<=0 && sprintf(text, "Time Up!");


Now you should be set :D
Attachments
img.jpg
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Set up a timer without using If statements

Postby gustavo02 » Thu May 01, 2014 8:23 pm

Thanks, that script just saved my life today.
gustavo02
 
Posts: 6
Joined: Tue Feb 12, 2013 8:22 pm
Score: 0 Give a positive score

Re: Set up a timer without using If statements

Postby Hblade » Sun May 04, 2014 4:23 am

You're welcome
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest