|
Re: frames/seconds since function started?
[Re: Lukas]
#298625
11/16/09 14:58
11/16/09 14:58
|
Joined: Jul 2007
Posts: 959 nl
flits
User
|
User
Joined: Jul 2007
Posts: 959
nl
|
you got those functions only for the game itself
total_frames & total_ticks
"empty"
|
|
|
Re: frames/seconds since function started?
[Re: flits]
#298644
11/16/09 17:21
11/16/09 17:21
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
Expert
|
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
a better way than to increment that thing would, in my oppinion, be:
void theFunction()
{
var startingTicks = total_ticks;
var ticksPassedSinceStart;
while(1)
{
//do something
if(blah)
{
ticksPassedSinceStart = total_ticks - startingTicks;
}
wait(1);
}
}
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: frames/seconds since function started?
[Re: Germanunkol]
#298664
11/16/09 19:06
11/16/09 19:06
|
Joined: Nov 2007
Posts: 1,143 United Kingdom
DJBMASTER
OP
Serious User
|
OP
Serious User
Joined: Nov 2007
Posts: 1,143
United Kingdom
|
Hmmm, i'm trying to find the simplest solution that can accomodate for both frames and seconds. Here is my code so far...
var alarm_timer = 0;
while(1)
{
if(alarm_timer == 10) // after 10 frames have passed
{
beep();
}
if(alarm_timer == 20) // after 20 frames have passed
{
beep();
}
alarm_timer += time_step; // or time_frame?
wait(1);
}
But this is buggy, because it sometimes beeps and sometimes doesn't. I think i may be getting confused with time_step and time_frame. I'm not 100% sure what the difference is between them.
Last edited by DJBMASTER; 11/16/09 19:07.
|
|
|
Re: frames/seconds since function started?
[Re: Lukas]
#298668
11/16/09 20:01
11/16/09 20:01
|
Joined: Nov 2007
Posts: 1,143 United Kingdom
DJBMASTER
OP
Serious User
|
OP
Serious User
Joined: Nov 2007
Posts: 1,143
United Kingdom
|
For seconds, add time_step/16 each frame. Yeh i originally tried that but it doesn't always work when using it in a comparison statement...
var alarm_timer = 0;
while(1)
{
if(alarm_timer == 5) // after 5 seconds
{
beep();
}
alarm_timer += time_step / 16;
wait(1);
}
It seems to only work sometimes, and not 100% of the time.
|
|
|
|