Second/Time question

Posted By: DestroyTheRunner

Second/Time question - 08/25/08 21:01

I know its noobish... but I searched over the forum but coundt find it.

Simple thing, I want add 1 to the variable every second BUT without using stuff like, sleep or wait(-1) or total_secs.

here´s the example:
Code:
var seconds;
...
while(1)
{
seconds += ?? ; 
wait(1);
}


I´ve tried stuff like 'seconds = time_step/16' and 'seconds = time_frame/16' but its not acuratte at all.

help?
Posted By: badapple

Re: Second/Time question - 08/26/08 08:05

you could use sys_seconds maybe
Posted By: delinkx

Re: Second/Time question - 08/26/08 08:26

yeah maybe u can try with sys_seconds.. something like:

var secs;
secs = sys_seconds;
while(secs != sys_seconds)
{
my_variable++;
secs = sys_seconds;
}



not tested .. just giving u an idea.
Posted By: Anonymous

Re: Second/Time question - 08/26/08 08:41


well, since sys_seconds goes from
0 to 59...which is 1 to 60. wink

when sys_seconds is equal to 59
or even when sys_seconds changes again back to 0
update or add 1 to your variable.
Posted By: delinkx

Re: Second/Time question - 08/26/08 09:15

Originally Posted By: cemetarycat

well, since sys_seconds goes from
0 to 59...which is 1 to 60. wink

when sys_seconds is equal to 59
or even when sys_seconds changes again back to 0
update or add 1 to your variable.


@cemetarycat:

mate, he wants to count no. of seconds. ur algorithm is for updating every one minute.
Posted By: Anonymous

Re: Second/Time question - 08/26/08 09:26

meowwww! smile
now I see.


cheers


so get/retrive current system time at run time or perhaps when entering a function..if the algorithm is in function.
assign it as start time.
then count off 1000 milliseconds...since there is 1000 miliseconds in a second. Update your variable.
update your start time then for new current
system time. Repeat.
I have done this in other languages like Blitz3d, Cobra/Cobra 3d, Pure Basic, and even Dark Basic too.

But looking in the online manual
and in the Predefined variables under Time
total_ticks looks good.
but especially the timer function wink








Posted By: Anonymous

Re: Second/Time question - 08/26/08 10:17


okay,

here is a code snippet.

Code:
 ////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>

////////////////////////////////////////////////////////////////////

var update_var=0;

PANEL* first_pan =
{
	digits (10, 20, 2, *, 1, sys_seconds);
	
	digits(20, 50,4, *, 1, update_var);
	
	digits ( 70, 200, 2, *, 1, sys_hours);
   digits ( 90, 200, 2, *, 1, sys_minutes);
   digits ( 110, 200, 2, *, 1, sys_seconds);
	
	 
	flags = VISIBLE;
}

/////////////////////////////////////////////////////////////////////

function main()
{
	
	var start_base;
	video_mode = 7; 
	screen_color.blue = 150;
	
	 start_base=sys_seconds;
	
	while(1)
	{
		if (sys_seconds != start_base)
		{
			update_var+=1;
			start_base=sys_seconds;
			
			
		}
		
		wait(1);
		
	}
	
	
}



and kudos and cheers to delinkx.
Posted By: DestroyTheRunner

Re: Second/Time question - 08/26/08 20:21

thanks for all your replies but when I said
Quote:

...BUT without using stuff like, sleep or wait(-1) or total_secs.

I meant I didnt want to use any predefined variable and ,yes through math calculations like "time_step/16" as i read in another random post but doest seem to work.

is this possible to without using the predefined?

thanks smile
Posted By: mpdeveloper_B

Re: Second/Time question - 08/26/08 21:17

you will still need to use time_step because this will make it where the time is exactly the same all the time unless your framerate is less than 4 or something.

I'm assuming that you want to see the seconds like this: XX.xxx? Is that why you want it like that?
Posted By: DestroyTheRunner

Re: Second/Time question - 08/26/08 22:20

i think im not expressing myself very clearly.
Im sorry!

lets start over:

how can I add 1 to the variable X every second?
like


X += 1*every second.

without using thoses 'sys_this, sys_that...' predefinedes..

I know ill probably need to use time_step, i just dont want to use those SYS predefines..
smile
Posted By: Anonymous

Re: Second/Time question - 08/27/08 00:04


I think its the timer function.

var start_base=timer();

and it returns in microseconds
rather in milliseconds. But the same principle
is the same to count and measure them.

and here is the code.
try different values for the literal number value that is added to start_base.

Code:
 ////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>

////////////////////////////////////////////////////////////////////

var update_var;

PANEL* first_pan =
{
	digits (10, 20, 2, *, 1, sys_seconds);
	
	
	 digits(20,100, 10.2, *, 1, update_var);
	
	digits ( 70, 200, 2, *, 1, sys_hours);
   digits ( 90, 200, 2, *, 1, sys_minutes);
   digits ( 110, 200, 2, *, 1, sys_seconds);
	
	 
	flags = VISIBLE;
}

/////////////////////////////////////////////////////////////////////

function main()
{
	
	var  start_base=timer();
	video_mode = 7; 
	screen_color.blue = 150;
	

	
	while(1)
	{
		
		 
		  if (  ( timer()>start_base+5000) )
		  {
		  	
		  	 update_var+=1;
		  	 start_base=timer();
		  	
		  	
		}	
		 	
		 	
		
		
		
		
		
				
		wait(1);
		
	}
	
	
}



cheers


Posted By: MrGuest

Re: Second/Time question - 08/27/08 15:07

lol, you'll need some kind of preset seconds to check
Code:
var global_timer = 0;

function fnc_counter(){
	while(1){
		global_timer += 1;
		wait(-1);
	}
}

//or
var global_second;
function fnc_counter(){
	global_second = sys_seconds;
	while(1){
		if(sys_seconds != global_second){
			//do your function
		}
	}
}


hopefully that's what you're after
Posted By: testDummy

Re: Second/Time question - 08/27/08 19:26

!?
It was tested a bit.
Code:
var tm_n1 = 0;
var tm_n2 = 0;
var tm_n3 = 0;
function tmf_secNext() {
	tm_n3 += 1;
	//spof_n1("tm_n3: ", tm_n3);
	//spof_n1("sys_seconds: ", sys_seconds);
}
function tmf_count() {
	while(1) {
		tm_n2 = total_ticks / 16;
		if ((tm_n2 - tm_n1) > 1) {
			tm_n1 = tm_n2;
			tmf_secNext();
		}
		wait(1);
	}
}

Posted By: DestroyTheRunner

Re: Second/Time question - 08/29/08 17:37

sorry guys , I had some others issues to take care, this 'clock' thing was only for testing purposes.
I havent find the answer yet, but im not using lite-c so i dont think i can use stuff like cemeterycat said
"
#include <acknex.h>
#include <default.c>
"

and i dont want to make my game to 'freeze' one second by calling WAIT(-1) i just wanted to it constantly add seconds to the timer, like for measuring a entire lap in a race game, anyway next week ill be searching in the AUMs I heard there is something about time in there.

Thanks for all your replies smile smile
Posted By: testDummy

Re: Second/Time question - 08/29/08 18:56

Added missing wait(1) in code posted by THIS (above or previous page).
Put code which should be run approximately once a sec, in function tmf_secNext!?
Quoting DestroyTheRunner.
Quote:
I´ve tried stuff like 'seconds = time_step/16' and 'seconds = time_frame/16' but its not acuratte at all.

But not total_ticks / 16!?
AUM 16 timer / counter
It uses total_ticks also, but 'you' should probably look through each AUM (or use an index) anyway.


Posted By: Bot190

Re: Second/Time question - 08/29/08 23:06

as far as i know wait(-1) does not pause the whole game. also, why don't you want to use a predefined variable?
Posted By: MrGuest

Re: Second/Time question - 08/30/08 17:25

The only time it will pause the whole game is if you have everything being updated from 1 function, which has the wait(-1) in...

Do you know about creating/calling seperate functions, of which 1 could just be a simple clock?
Posted By: DestroyTheRunner

Re: Second/Time question - 09/01/08 19:03

omg!
im so stupid...
thats it, it is easier just to call it in another function...
crazy

Code:
function stupid_function()
{
   while(1)
   {
   seconds += 1;
   wait(-1);
   }   
}

simple frown

sorry make you guys lose your time anwsering this.
but thanks!!
Posted By: sadsack

Re: Second/Time question - 09/06/08 17:19

What I am looking for is just the time printed out on the screen how long the game/program been running. in lite-c
renny
Posted By: DJBMASTER

Re: Second/Time question - 09/06/08 17:34

just use a panel with total_secs in a digits element...

something like...

PANEL* total_time =
{
pos_x=0;
pos_y=0;
layer=1;
digits(0,0,5,*,1,total_secs);
flags = VISIBLE;
}
© 2024 lite-C Forums