# regulating speed in a game

can anyone tell me the most efective way to regulate speed in QB4.5?
I find it kind of dificult, since all computers are different speeds
I've been using this routine up until now:

'
thetime& = TIMER
DO
sec& = sec& + 1
LOOP until TIMER => thetime& + 1
'

and this gets the amount of loops the CPU can get in one second
and stores it in sec&
and make a FOR NEXT loop:

FOR i& = 1 to sec& / RoomSpeed
NEXT

to interupt the play of the game

this works fine on most computers, but it's really fast on some others
is there a better way to get processor independence?

Jony_Basic

• : can anyone tell me the most efective way to regulate speed in QB4.5?
: I find it kind of dificult, since all computers are different speeds
: I've been using this routine up until now:
:
: '
: thetime& = TIMER
: DO
: sec& = sec& + 1
: LOOP until TIMER => thetime& + 1
: '
:
: and this gets the amount of loops the CPU can get in one second
: and stores it in sec&
: and make a FOR NEXT loop:
:
: FOR i& = 1 to sec& / RoomSpeed
: NEXT
:
: to interupt the play of the game
:
: this works fine on most computers, but it's really fast on some others
: is there a better way to get processor independence?
:
: Jony_Basic
:
[green]I am not claiming to be an experto n BASIC, but processor speed does not tell the tale. for instance sec/roomspeed will take more than uno loop to complete, and the for loop may be computing sec/roomspeed every loop. furthermore if the next line is dependent on sec/roomspeed as a condition there is precious time involved.[/green] A better implementation would be 1) add desired interval to timer. 2) output to driver or get input from user 3) compare computed time to current time.

to make a good game efficient, it is important to differentiate between computations and data flow. Once that distinction is made there is a see-saw effect between the two that should occur. Even the computations involve loading from memory, unless you are making good use of local variables. Yet and Still, the timer must be loaded, so I put computed time first in the comparison. if you skip step 2 then 3 should be compare current time to computed time, so the processor fetches the current time while the computed time is being computed. I hope you catch my drift. BASIC is simple to use, but at times it's functionality takes away from an understanding of what is happening underneath it all. well, I hope you liked my short story
[green]WHAT you;see_is_what=you.get;[/green]
-Russ aka DangeRuss

• : can anyone tell me the most efective way to regulate speed in QB4.5?
: I find it kind of dificult, since all computers are different speeds
: I've been using this routine up until now:
:
: '
: thetime& = TIMER
: DO
: sec& = sec& + 1
: LOOP until TIMER => thetime& + 1
: '
:
: and this gets the amount of loops the CPU can get in one second
: and stores it in sec&
: and make a FOR NEXT loop:
:
: FOR i& = 1 to sec& / RoomSpeed
: NEXT
:
: to interupt the play of the game
:
: this works fine on most computers, but it's really fast on some others
: is there a better way to get processor independence?
:
: Jony_Basic
:
Hey, long time no see.

I got this problem also too a while back. Your solution assumes that the proccessor speed is the same, wich it isn't, a computer with windows XP will run very different depending on user input.
To make it work for real do something like this:
[code]
breaktime = TIMER + .1 'delay
do
while TIMER < breaktime
[/code]
If the compiler/interpreter is good this could be very optimised.

[grey]The one and only [b]Niklas Ulvinge[/b][/grey] [white]aka [b]IDK[/b][/white]