Timing

Discuss whatever you want here--both QB and non-QB related. Anything from the DEF INT command to the meaning of life!

Moderators: Pete, Mods

Post Reply
User avatar
floogle11
Veteran
Posts: 71
Joined: Sat May 02, 2009 7:08 pm
Location: Zorgon planet
Contact:

Timing

Post 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.
Go to my Qbsite its: Trueqb.webs.com
Or if you play nazi zombies go to www.Nazizombys.com and register for cheats, hints, and strategys.
User avatar
BigBadKing
Veteran
Posts: 83
Joined: Fri Oct 09, 2009 12:39 pm
Location: Space
Contact:

Post 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!
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Try just using TIMER

Post 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.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Post Reply