Timming issues - Millisecs()

Blitz3D Forums/Blitz3D Beginners Area/Timming issues - Millisecs()

Dax Trajero(Posted 2004) [#1]
Being a newbie, I'm wondering if everyone uses the same methods for the in-game timers ?

eg.

; this code starts my timer
player(1)\accel_timer = Millisecs() ; start timer
player(1)\accel_flag = true

; check if timer has reached designated time
if millisecs() - player(1)\accel_timer => 60
player(1)\accel_timer = 0 ; stop timer
player(1)\accel_flag = false
end if

Is this a reliable method, or is there another way ?


Rob Farley(Posted 2004) [#2]
I'm not sure what you're trying to achieve here. You want to explain what the problem is rather than suggesting a solution.


Dax Trajero(Posted 2004) [#3]
sorry, I'll explain...

during my game I have a various timers that are used for things like accelerating a car sprite and braking a car sprite

if the user presses the accelerate key, then I start a timer running....

player(1)\accel_timer = millisecs()

during the main loop I check the status of that timer to see if 60ms have elapsed...

if millisecs() - player(1)\accel_timer =>60

if they have, I run so code to increment the car's gear.

I'm just wondering if everyone uses simple timers like these ?


Dax Trajero(Posted 2004) [#4]
this is the first code and the first game I've ever written so the whole concept of timing in my game is complete guesswork. I just want confirmation this is how other people do it too!


Rob Farley(Posted 2004) [#5]
Timers are used throughout pretty much any game.

Your use of timers however I'm still slightly hazy about what you're trying to achieve.

For timing of game play you either want to use delta timing or set the amount of updates per second of your game loop.

Regarding your gear changing thing, I would suggest that you have a revs and targetrevs value and do something like: (psuedo code)

if accelerate key_is_pressed then increment targetrevs else decrement targetrevs
if revs<1000 and gear > 1 then gear = gear - 1 : targetrevs = 8000
if revs<1000 and gear = 1 then targetrevs = 10000
if revs>8000 and gear < 6 then gear = gear + 1: targetrevs=1500
revs = (targetrevs-revs)/100 ; rev smoothing

I'll write a proper bit of code later... but got to go home first!


Dax Trajero(Posted 2004) [#6]
ok, what am I trying to achieve in this instance ?

answer - to make sure the "gear" variable is incremented exactly every 60ms

reagrdless of what I do with the variable "gear" I just want to know that I'm using the right method in order to increment a variable after exactly 60ms


Rob Farley(Posted 2004) [#7]
Then it should work, but changing gear every 60ms sounds very very fast, that's over 16 gear changes per second.


Rob Farley(Posted 2004) [#8]
Anyway... As promised!




Dax Trajero(Posted 2004) [#9]
cheers Rob!

If I added that the game is in 2D, runs at 60fps and the cars are tiny sprites, would it make any sense ?

thanks again!