1 registered members (AndrewAMD),
1,014
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: frames/seconds since function started?
[Re: DJBMASTER]
#298682
11/16/09 22:05
11/16/09 22:05
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
Change the comparison statement:
var alarm_timer = 0;
while(1)
{
if(alarm_timer >= 5) // after 5 seconds
{
beep();
}
alarm_timer += time_step / 16;
wait(1);
}
This way, it is still caught if it skips 5 altogether. Jibb
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: frames/seconds since function started?
[Re: JibbSmart]
#298691
11/16/09 23:05
11/16/09 23:05
|
Joined: Nov 2007
Posts: 1,143 United Kingdom
DJBMASTER
OP
Serious User
|
OP
Serious User
Joined: Nov 2007
Posts: 1,143
United Kingdom
|
Already thought of that. It will fire continuously after 5 seconds. Setting 'alarm_timer = 0;' will fix this but any comparison tests after this, will not be met.
Last edited by DJBMASTER; 11/16/09 23:07.
|
|
|
Re: frames/seconds since function started?
[Re: DJBMASTER]
#298700
11/17/09 00:32
11/17/09 00:32
|
Joined: Apr 2009
Posts: 27 Silicon Valley
Dillinger
Newbie
|
Newbie
Joined: Apr 2009
Posts: 27
Silicon Valley
|
"any comparison tests after this, will not be met" Not quite sure what you mean by that. I'm guessing yeah, if you need to still access either the timer or the flipped switch, you'll probably need to declare a whole 'nother variable. Hope that doesn't blow your memory budget. Since I'm uncertain exactly what you want to do, here's the kitchen sink:
var alarm_timer = 0 ;
var my_switch = 1 ;
var my_counter = 0 ;
var elapsed_time = 0 ;
if ( my_switch == 1 ) elapsed_time = 0 ;
while ( my_switch == 1 )
{
alarm_timer += time_step / 16 ;
elapsed_time = alarm_timer ; // copy time into display variable
if(alarm_timer >= 5) // after 5 seconds
{
beep();
alarm_timer = 0 ; // reset timer for next time
my_switch = 0 ; // turn off the alarm
my_counter++ ; // log how many times alarm has been triggered
}
wait(1);
}
|
|
|
Re: frames/seconds since function started?
[Re: DJBMASTER]
#298725
11/17/09 08:59
11/17/09 08:59
|
Joined: Mar 2006
Posts: 3,538 WA, Australia
JibbSmart
Expert
|
Expert
Joined: Mar 2006
Posts: 3,538
WA, Australia
|
Already thought of that. It will fire continuously after 5 seconds. Setting 'alarm_timer = 0;' will fix this but any comparison tests after this, will not be met. Will you need more than one of these functions running simultaneously? If so, you'll also want a way to stop the timer for each of those. Jibb
Formerly known as JulzMighty. I made KarBOOM!
|
|
|
Re: frames/seconds since function started?
[Re: DJBMASTER]
#298806
11/18/09 05:39
11/18/09 05:39
|
Joined: Oct 2002
Posts: 2,256 Oz
Locoweed
Expert
|
Expert
Joined: Oct 2002
Posts: 2,256
Oz
|
Think this is closer to what you want.
var framesCheck = 0;
var secondsCheck = total_secs;
while(1)
{
if(framesCheck == 10) // after 10 frames have passed
{
framesCheck = 0;
beep();
}
if(total_secs >= (secondsCheck+5)) // after 5 seconds have passed
{
secondsCheck = total_secs;
beep();
}
framesCheck++;
wait(1);
}
Loco
Professional A8.30 Spoils of War - East Coast Games
|
|
|
Re: frames/seconds since function started?
[Re: Locoweed]
#298807
11/18/09 05:53
11/18/09 05:53
|
Joined: Oct 2002
Posts: 2,256 Oz
Locoweed
Expert
|
Expert
Joined: Oct 2002
Posts: 2,256
Oz
|
Or actually after reading your original post.
var framesCheck = 0;
var secondsCheck = total_secs;
STRING* strFrames = "#30";
STRING* strSeconds = "#30";
while(1)
{
str_for_num(strFrames, frameCheck);
draw_text(strFrames,0,50,vector(250,0,0));
str_for_num(strSeconds, (total_secs-secondsCheck));
draw_text(strSeconds,0,70,vector(250,0,0));
framesCheck++;
wait(1);
}
Although the frames counter will rack up like you are pumping gas. Loco
Professional A8.30 Spoils of War - East Coast Games
|
|
|
Re: frames/seconds since function started?
[Re: Locoweed]
#298868
11/18/09 15:20
11/18/09 15:20
|
Joined: Nov 2007
Posts: 1,143 United Kingdom
DJBMASTER
OP
Serious User
|
OP
Serious User
Joined: Nov 2007
Posts: 1,143
United Kingdom
|
Think this is closer to what you want.
var framesCheck = 0;
var secondsCheck = total_secs;
while(1)
{
if(framesCheck == 10) // after 10 frames have passed
{
framesCheck = 0;
beep();
}
if(total_secs >= (secondsCheck+5)) // after 5 seconds have passed
{
secondsCheck = total_secs;
beep();
}
framesCheck++;
wait(1);
}
Loco Almost, but it will beep every 5 seconds. I may have to re-think my logic on this mechanism...
|
|
|
Re: frames/seconds since function started?
[Re: DJBMASTER]
#302569
12/20/09 14:50
12/20/09 14:50
|
Joined: Oct 2004
Posts: 900 Lgh
rojart
User
|
User
Joined: Oct 2004
Posts: 900
Lgh
|
Thanks, that is useful, but unfortunately i can't limit the fps. Hmm, I'm not really sure what your goal is, but I've no problem to limit the fps with this code:
//#include <acknex.h>
#include <default.c>
function my_limit_startup()
{
fps_max = 60; int my_fps = 1;
while(my_fps<10) // limit me to 10s
{
if ((total_frames % 60) == 1) my_fps++;
if ((total_frames % 300) == 1) beep(); // repeat the beep sound after 5s
wait(1);
}
}
|
|
|
|