Page 1 of 1

Timing

Posted: Wed Nov 04, 2009 11:32 am
by floogle11
Im making a game were you have resources and you gain them each tick
(a tick is like a turn but timed) but im not good with timing can someone tell me how to control the timing in Qbasic. All i know is TIMER ON, TIMER OFF, TIMER STOP, ON TIMER(10,or any other number) a command here, and thats it.
Thank you.

Posted: Wed Nov 04, 2009 3:02 pm
by BigBadKing
The Big and Bad King is back with a solution, here it is:

Code: Select all

' clear the screen and turn on the timer
CLS
TIMER ON

' setup the maximum food and food
max = 30
food = 29

' every three seconds, goto label Yummy
ON TIMER(3) GOSUB Yummy

' start loop!
DO
 ' if food is changed, then print the remaining foods
 IF food < max THEN max = food: PRINT "You have"; food; "mens remaining"

' end loop if any key is pressed!
LOOP WHILE INKEY$ = ""
END


' the label which the timer goes to!
Yummy:

' subtract one from variable food
  food = food - 1

' say that you ate one of your men!!!
  PRINT "You ate one of your men!"
RETURN
if i didnt understand badly, you want a game that every. E.G 3 seconds,
your character eats some food. right? this is atleast the solution i gave
you, you can change it as you like!

Try just using TIMER

Posted: Wed Nov 04, 2009 6:35 pm
by burger2227
TIMER can go as slow as 1/18th a second or .05 seconds roughly using a SINGLE value.

Code: Select all

DEFSNG A-Z ' placed before the SUB only. QB may try to add DEFINT.
SUB Delay (dlay!)

start! = TIMER
DO WHILE start! + dlay! >= TIMER
IF start! > TIMER THEN start! = start! - 86400 ' midnight adjustment
LOOP

END SUB
To CALL the SUB use: Delay .1 ' 1/10th second

You can use a similar delay loop in the main module also if you need code inside of the loop.