Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,014 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
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
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
Change the comparison statement:
Code:
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 Offline OP
Serious User
DJBMASTER  Offline 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] #298698
11/17/09 00:10
11/17/09 00:10
Joined: Oct 2004
Posts: 900
Lgh
rojart Offline
User
rojart  Offline
User

Joined: Oct 2004
Posts: 900
Lgh
Maybe this code helps:
Code:
#include <acknex.h>
#include <default.c>

function main()
{
	fps_max = 60;
	// repeat the beep sound after 5s every time, play with 300 and 60
	while(1)
	{
		if ((total_frames % 300) == 1) beep();	
		wait(1);
	}
}




Regards, Robert

Quote
Everything should be made as simple as possible, but not one bit simpler.
by Albert Einstein

PhysX Preview of Cloth, Fluid and Soft Body

A8.47.1P
Re: frames/seconds since function started? [Re: rojart] #298699
11/17/09 00:14
11/17/09 00:14
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline OP
Serious User
DJBMASTER  Offline OP
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
Thanks, that is useful, but unfortunately i can't limit the fps. This whole thing is for more my application 3DGS Easy Scripter, so if i seem to reject ideas it's because i'm trying to build a generic framework that can fire events at certain frames/seconds elapsed since the start of an action.

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
D
Dillinger Offline
Newbie
Dillinger  Offline
Newbie
D

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:

Code:
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
J
JibbSmart Offline
Expert
JibbSmart  Offline
Expert
J

Joined: Mar 2006
Posts: 3,538
WA, Australia
Originally Posted By: DJBMASTER
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
L
Locoweed Offline
Expert
Locoweed  Offline
Expert
L

Joined: Oct 2002
Posts: 2,256
Oz
Think this is closer to what you want.

Code:
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
L
Locoweed Offline
Expert
Locoweed  Offline
Expert
L

Joined: Oct 2002
Posts: 2,256
Oz
Or actually after reading your original post.

Code:
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. wink

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 Offline OP
Serious User
DJBMASTER  Offline OP
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
Originally Posted By: Locoweed
Think this is closer to what you want.

Code:
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 Offline
User
rojart  Offline
User

Joined: Oct 2004
Posts: 900
Lgh
Originally Posted By: DJBMASTER
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:
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);
	}
}




Regards, Robert

Quote
Everything should be made as simple as possible, but not one bit simpler.
by Albert Einstein

PhysX Preview of Cloth, Fluid and Soft Body

A8.47.1P
Page 2 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1