Page 1 of 1

Stopinga countdown timer & getting that info

PostPosted: Mon Mar 26, 2012 10:07 am
by Antxion
I'm trying to stop a countdown timer once my player hits a checkpoint and then get that time to use in a bonus screen

Here is the code I'm using for the timer. I can't figure out how to stop it.

Global Script
Code: Select all
int SecLeft = 30;
int VirtSec = 30;
int NumFrames = 0;


Timer - Create Actor - Script
Code: Select all
sprintf(text, "%i", VirtSec);


Timer - Draw Actor - Script
Code: Select all
if(NumFrames >= real_fps)
{
    if(SecLeft > 0)
    {
        SecLeft -= 1;
        if(VirtSec <= 0)
        {
            VirtSec = 59;
        }
        else
        {
            VirtSec -= 1;
        }
        sprintf(text, "%02d", VirtSec);
    }
    NumFrames = 0;
}
else
{
    NumFrames += 1;
}

Re: Stopinga countdown timer & getting that info

PostPosted: Mon Mar 26, 2012 3:10 pm
by SuperSonic
Is that the code from my tutorial that you're using? ^^

Ok, here's what you have to do. In your global code, put this:
Code: Select all
int TimerOn = 1;

Then, on your collision event, put this:
Code: Select all
TimerOn = 0;

Finally, for your draw actor event, replace it with this:
Code: Select all
if(TimerOn)//Notice how I simply added an if statement to check whether or not the timer is on
{
    if(NumFrames >= real_fps)
    {
        if(SecLeft > 0)
        {
            SecLeft -= 1;
            if(VirtSec <= 0)
            {
                VirtSec = 59;
            }
            else
            {
                VirtSec -= 1;
            }
            sprintf(text, "%02d", VirtSec);
        }
        NumFrames = 0;
    }
    else
    {
        NumFrames += 1;
    }
}
Hope that helps :wink:

Re: Stopinga countdown timer & getting that info

PostPosted: Mon Mar 26, 2012 9:43 pm
by Antxion
+1
Yeah that was your code from your tutorial.
Thanks so much supersonic ,you really are super, thats really been bugging me.

Re: Stopinga countdown timer & getting that info

PostPosted: Mon Mar 26, 2012 10:18 pm
by SuperSonic
Thanks for the point, and no problem. I'm glad I could help :wink:

Re: Stopinga countdown timer & getting that info

PostPosted: Tue Mar 27, 2012 2:15 am
by Johnno
oooh nice, I'm going to use that. Thanks SuperSonic
+1

Re: Stopinga countdown timer & getting that info

PostPosted: Tue Mar 27, 2012 2:48 am
by SuperSonic
Johnno wrote:oooh nice, I'm going to use that. Thanks SuperSonic
+1
Haha, no problem. And thank you for the point :P