|
|
timer
#230358
10/05/08 00:00
10/05/08 00:00
|
Joined: Aug 2008
Posts: 408 mi usa
sadsack
OP
Senior Member
|
OP
Senior Member
Joined: Aug 2008
Posts: 408
mi usa
|
Hello, I need timer that starts at 0 when the game starts and don't stop ontill the game is over.
#include <acknex.h>
#include <default.c>
#include <windows.h>
float time_passed;
STRING* time_str = "#30";
TEXT* time_txt =
{
layer = 15;
pos_x = 10;
pos_y = 20;
string (time_str);
flags = VISIBLE;
}
function main()
{
video_mode = 6; // create a program window of 640x480 pixels
vec_set(screen_color, vector(0, 0, 0)); // make the background color dark
while (1)
{
time_passed = GetTickCount() * .1;
str_for_num(time_str, time_passed);
wait (1);
}
}
I tryed to have it start at 0 by doing something like this: time_passed = 0 but it all ways start out with time on it. If anyone can see what I am doing wrong, let me know. there is not much in the manual about timers. Thank You renny
I have A7 Commercial .............. Now I just need to learn how to use it
|
|
|
Re: timer
[Re: sadsack]
#230360
10/05/08 00:04
10/05/08 00:04
|
Joined: Jan 2008
Posts: 1,580
Blade280891
Serious User
|
Serious User
Joined: Jan 2008
Posts: 1,580
|
could it be something like STRING* time_passed = 0 while(1) { wait(-1) time_passed ++ }
My Avatar Randomness V2"Someone get me to the doctor, and someone call the nurse And someone buy me roses, and someone burned the church"
|
|
|
Re: timer
[Re: Blade280891]
#230422
10/05/08 13:31
10/05/08 13:31
|
Joined: Feb 2006
Posts: 385 Oldenburg,Germany
Ralph
Senior Member
|
Senior Member
Joined: Feb 2006
Posts: 385
Oldenburg,Germany
|
You can use this engine functions: "total_frames" or "total_ticks" or "total_secs" Search at them in the Manual.
Ralph
Last edited by Ralph; 10/05/08 13:32.
|
|
|
Re: timer
[Re: Ralph]
#230448
10/05/08 15:35
10/05/08 15:35
|
Joined: Aug 2008
Posts: 408 mi usa
sadsack
OP
Senior Member
|
OP
Senior Member
Joined: Aug 2008
Posts: 408
mi usa
|
Thank you Blade and ralph,
I looked in the manaul for timer not total stuff. renny
I have A7 Commercial .............. Now I just need to learn how to use it
|
|
|
Re: timer
[Re: sadsack]
#230452
10/05/08 15:49
10/05/08 15:49
|
Joined: Aug 2008
Posts: 408 mi usa
sadsack
OP
Senior Member
|
OP
Senior Member
Joined: Aug 2008
Posts: 408
mi usa
|
Ralph, total_secs work ok for now thanks. renny
I have A7 Commercial .............. Now I just need to learn how to use it
|
|
|
Re: timer
[Re: sadsack]
#230481
10/05/08 19:42
10/05/08 19:42
|
Joined: Sep 2008
Posts: 66
falagar8
Junior Member
|
Junior Member
Joined: Sep 2008
Posts: 66
|
@sadsack, you can use timer() but its not very reliable in timer measuring and on occassion...glitchy. And as Ralph has said.... you might find this useful
#include <acknex.h>; //You need these includes at the start of your main script.
#include <default.c>;
//creating a Text Object on the fly..or near that fly ;)
STRING* name1="#25";
STRING* namor="#35";
STRING* name2a="#70";
var time_passed;
var start_time;
var clocker=0;
var set_of_10ticks=0;
TEXT* mytext={
font="Arial#20";
strings=2;
}
function main()
{
//This section happens once when the function is run initially
level_load("");
wait(3); //Wait required for level load
//sorta create the near Text object on the fly...at run time.
mytext.red=10;
mytext.green=255;
mytext.blue=10;
mytext.pos_x=100;
mytext.pos_y=50;
mytext.layer=0;
mytext.flags=VISIBLE;
str_cpy((mytext.pstring)[1], "Falagar" );
start_time=timer();
total_ticks=0;
str_cpy(namor, " ");
while(1)
{
//This section happens every frame due to a while loop.
//process every approx 10 or so ticks
//get a snapshot of the time..in timer() for the 10 ticks or so.
//place the number of 10 ticks or so...in the var of set_of_10ticks
if(total_ticks>=10)
{
clocker++;
str_for_num(name1, clocker);
str_cpy(namor, " ");
str_cat(namor, name1);
str_cpy( (mytext.pstring)[0], namor);
start_time=timer();
total_ticks=0;
set_of_10ticks++;
str_for_num(name2a, set_of_10ticks);
str_cat(name2a, " sets of 10 ticks");
str_cpy( (mytext.pstring)[1], name2a);
}
wait(1);
}
}
I could of displayed just one line and left the other blank or with something else. But, I wanted to do some formatting and extra displaying/printing too.
|
|
|
Re: timer
[Re: falagar8]
#230491
10/05/08 23:42
10/05/08 23:42
|
Joined: Aug 2008
Posts: 408 mi usa
sadsack
OP
Senior Member
|
OP
Senior Member
Joined: Aug 2008
Posts: 408
mi usa
|
Hi falagar8, I tryed your code, will not compile. Gives no reason for not compiling. Will look at it tomorrow and see if I can see why it does not compile. Thank You renny P.S. Sorry but I have problems with a if statement that I can't get to work right now.
I have A7 Commercial .............. Now I just need to learn how to use it
|
|
|
Re: timer
[Re: sadsack]
#230495
10/06/08 00:54
10/06/08 00:54
|
Joined: Sep 2008
Posts: 66
falagar8
Junior Member
|
Junior Member
Joined: Sep 2008
Posts: 66
|
Definitely, works for me. And I'm in Paradise Valley with only using the Lite C freeware version. Could it be the version you are using? Also check for any missing semicolons and brackets. I know I miss a few now and then.  And equivalence with a if statement is the same as in Pascal....with == rather than with just a single =. Of course assignment in Pascal is := rather than = here are some screenshots for confirmation:  
|
|
|
Re: timer
[Re: falagar8]
#230506
10/06/08 09:45
10/06/08 09:45
|
Joined: Sep 2008
Posts: 66
falagar8
Junior Member
|
Junior Member
Joined: Sep 2008
Posts: 66
|
I also took out the level_load(""); and replace it with the following statements video_mode=7; //800 x 600 vec_set(screen_color, vector(100,10,100) ); and also kept the wait(3); statement too. still works.  and for the light purple background. 
|
|
|
Re: timer
[Re: falagar8]
#230530
10/06/08 14:30
10/06/08 14:30
|
Joined: Aug 2008
Posts: 408 mi usa
sadsack
OP
Senior Member
|
OP
Senior Member
Joined: Aug 2008
Posts: 408
mi usa
|
I found the problem, got it working. when I copyed it I left of one of the #. put it back on and it worked fine. Thank you renny
I have A7 Commercial .............. Now I just need to learn how to use it
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|