Timing Help


jkgp2x

Still Fresh
Joined
Feb 7, 2006
Messages
32
i have been trying to create a rhythm and im having trouble getting a precise timer for when an event should happen. Does anyone know how to make a good timing system so this game will work.
 
with set_fps you can set the maximum fps of the game, you set it to a certain framerate, make sure your game isn't too heavy and you should be able to time it as you want i think
that is ofcourse if your game isn't so heavy you can't maintain that fps

there are also timers in fenix (they're timer[0] to timer[9] ), you could try using them (either setting them to 0 when you start, or by storing theit valua when you start, and then every time comparing it to the current value)
i'm not sure in which unit they work, i think in 100th's of a second, but experiment a bit :)
 
Use the fps variable. Eg.


For(time=0;time<fps*8;time++) Frame; End

Would work for 8 seconds, with time needing to be declared, and could be any variable, whereas fps automatically uses the current fps value.
 
i have somewhat of a timer in place. i set the fps to 100 and used the timer[0] function and it appears to give me 1/100 of second. how would i go about making it time in milliseconds instead of every 10 milliseconds.
 
jkgp2x posted on Mar 31 2006 at 06:35 PM said:
i have somewhat of a timer in place. i set the fps to 100 and used the timer[0] function and it appears to give me 1/100 of second. how would i go about making it time in milliseconds instead of every 10 milliseconds.
it's independent of the framerate, just every 100th of a second.
no way to speed that up i'm afraid. i hope it's accurate enough...
 
Last edited by a moderator:
ok im still having trouble with this. i made a program to make song steps in real time but when i run it back trough my game there are problems. when i clearly press a 2 buttons at different times it produces 2 objects on the screen at the same time. could someone take a look at my song maker sourcecode and tell me how to fix this.

program songmaker;
global
keys[20]=0;
buttons[500]=1;
timings[500]=0;
keyindex=0;
index=0;
push=1;
keydown=1;
keyleft=1;
keyright=1;
song;
string keyinput="bitches.ogg";
pause=1;
begin
set_mode(320,240,8);
set_fps(100,0);
titlescreen();
end

process titlescreen();
begin
song=load_song(keyinput);
load_fpg("new1.fpg");
put_screen("new1.fpg",1);
while(not(key(_alt)))
frame;
end
leveledit();

end
process leveledit()
begin
play_song(song,0);
timer[0]=0;
while(not(key(_space)))
if(not(key(_down)))keydown=1;end
if(not(key(_right)))keyright=1;end
if(not(key(_left)))keyleft=1;end
if(keyright==1)
if(key(_right))
keyright=0;
timings[index]=(timer[0]-109);
buttons[index]=3;
index++;
frame;
end
end
if(keyleft==1)
if(key(_left))
keyleft=0;
timings[index]=(timer[0]-109);
buttons[index]=1;
index++;
frame;
end
end
if(keydown==1)
if(key(_down))
keydown=0;
timings[index]=(timer[0]-109);
buttons[index]=2;
index++;
frame;
end
end
frame;
end
save("song.tim",timings);
save("song.but",buttons);
end
 
jkgp2x posted on Apr 3 2006 at 06:58 PM said:
ok im still having trouble with this. i made a program to make song steps in real time but when i run it back trough my game there are problems. when i clearly press a 2 buttons at different times it produces 2 objects on the screen at the same time. could someone take a look at my song maker sourcecode and tell me how to fix this.

program songmaker;
global
keys[20]=0;
buttons[500]=1;
timings[500]=0;
keyindex=0;
index=0;
push=1;
keydown=1;
keyleft=1;
keyright=1;
song;
string keyinput="bitches.ogg";
pause=1;
begin
set_mode(320,240,8);
set_fps(100,0);
titlescreen();
end

process titlescreen();
begin
song=load_song(keyinput);
load_fpg("new1.fpg");
put_screen("new1.fpg",1);
while(not(key(_alt)))
frame;
end
leveledit();

end
process leveledit()
begin
play_song(song,0);
timer[0]=0;
while(not(key(_space)))
if(not(key(_down)))keydown=1;end
if(not(key(_right)))keyright=1;end
if(not(key(_left)))keyleft=1;end
if(keyright==1)
if(key(_right))
keyright=0;
timings[index]=(timer[0]-109);
buttons[index]=3;
index++;
frame;
end
end
if(keyleft==1)
if(key(_left))
keyleft=0;
timings[index]=(timer[0]-109);
buttons[index]=1;
index++;
frame;
end
end
if(keydown==1)
if(key(_down))
keydown=0;
timings[index]=(timer[0]-109);
buttons[index]=2;
index++;
frame;
end
end
frame;
end
save("song.tim",timings);
save("song.but",buttons);
end

hmm... I think I understand the problem, try using one variable for all buttons, like, If(Not Key(_Left) And Not Key(_Right)....)
key=1; End

If(Key(_Left) and key)
key=0;
....

and so on and so forth
 
Last edited by a moderator:
Goity posted on Apr 3 2006 at 08:34 PM said:
jkgp2x posted on Apr 3 2006 at 06:58 PM said:
ok im still having trouble with this.  i made a program to make song steps in real time but when i run it back trough my game there are problems.  when i clearly press a 2 buttons at different times it produces 2 objects on the screen at the same time. could someone take a look at my song maker sourcecode and tell me how to fix this.

program songmaker;
global
keys[20]=0;
buttons[500]=1;
timings[500]=0;
keyindex=0;
index=0;
push=1;
keydown=1;
keyleft=1;
keyright=1;
song;
string keyinput="bitches.ogg";
pause=1;
begin
  set_mode(320,240,8);
  set_fps(100,0);
  titlescreen();
end

process titlescreen();
begin
song=load_song(keyinput);
load_fpg("new1.fpg");
put_screen("new1.fpg",1);
while(not(key(_alt)))
frame;
end
leveledit();

end
process leveledit()
begin
  play_song(song,0);
  timer[0]=0;
  while(not(key(_space)))
    if(not(key(_down)))keydown=1;end
      if(not(key(_right)))keyright=1;end
      if(not(key(_left)))keyleft=1;end 
    if(keyright==1)
    if(key(_right))
      keyright=0;
      timings[index]=(timer[0]-109);
      buttons[index]=3;
      index++;
      frame;
    end
    end
if(keyleft==1)
    if(key(_left))
      keyleft=0;
      timings[index]=(timer[0]-109);
      buttons[index]=1;
      index++;
      frame;
    end
    end
    if(keydown==1)                 
    if(key(_down))
      keydown=0;
      timings[index]=(timer[0]-109);
      buttons[index]=2;
      index++;
      frame;
    end
    end
frame;
end
save("song.tim",timings);
save("song.but",buttons);
end

hmm... I think I understand the problem, try using one variable for all buttons, like, If(Not Key(_Left) And Not Key(_Right)....)
key=1; End

If(Key(_Left) and key)
key=0;
....

and so on and so forth
nope, that's just some code to detect a key just once, so he won't get 10 keypresses everytime he presses the key

i don't see any mistakes to be honest..., but contact me on msn/icq (see pm), i'll see what i can do :)
 
Last edited by a moderator:
It`s really hard for me to figure out what the exact problem is...

Something with your key entry, right? And you press ONE button ONCE and get TWO objects? Is this your problem?

Goitys solution wouldn`t completely work then, if you want it to allow two different buttons at the same time.

Try this instead of your leveledit process:

Code:
process leveledit()
 private   
   down_pressed=false;
   left_pressed=false;
   right_pressed=false;

 begin
   play_song(song,0);
   timer[0]=0;
   while(!(key(_space)))     
     if(!(key(_down)))  down_pressed=false;  end;
     if(!(key(_right))) right_pressed=false; end;
     if(!(key(_left)))  left_pressed=false;  end;
           
     if(key(_right) and !right_pressed)
       timings[index]=(timer[0]-109);
       buttons[index]=3;
       index++;
       right_pressed=true;
       //frame; *dunno why this is here :P
      end;    
     if(key(_left) and !left_pressed)      
       timings[index]=(timer[0]-109);
       buttons[index]=1;
       index++;
       left_pressed=true;
       //frame; *~
      end;        
     if(key(_down) and !down_pressed)      
       timings[index]=(timer[0]-109);
       buttons[index]=2;
       index++;
       down_pressed=true;
       //frame; *~
      end;
     frame; //this frame should be enough
    end;
   save("song.tim",timings);
   save("song.but",buttons);
  end;

Be sure there is nothing else but the one leveledit process that uses these keys.
 
i figured out the problem. it was in the actual game and not the song editor program. now i got the timing right but there is a lag or skip when i play the game on the gp2x. That code is not the game but the level editor. what are some recommendations to stop a game from skipping
 
You can`t stop it from skipping on the 2X atm, it seems. Happens to me, too.

Maybe try different frameskip settings...
 
Goity posted on Apr 3 2006 at 09:34 PM said:
hmm... I think I understand the problem, try using one variable for all buttons, like, If(Not Key(_Left) And Not Key(_Right)....)
key=1; End

If(Key(_Left) and key)
key=0;
....

and so on and so forth

well it really can be done with less code when just using && (!key(_yourkey)):

Code:
IF (	  (key(_LEFT))   &&  (!key(_UP))  && (!key(_DOWN))	)
//code for moving left and ignoring up and down when left is pressed...
END
 
Last edited by a moderator:
Back
Top