Page 1 of 1

T IMER QUESTION

Posted: Fri Aug 03, 2007 5:16 pm
by Sinuvoid
Hey again, I was wondering how to make "TIMER" a varible so when it gets to a certain timeit does something

Example:

Code: Select all

DO
oldtime = TIMER 'makes the timer count up from zero
x = 3
y = 7
enemyx = 20
enemyy = 18

PRINT "TIME: "; INT(oldtime - TIMER)


LOCATE y, x
PRINT ".8."

IF TIMER = (this is the part im having trouble with) THEN
locate enemyy, enemyx
PRINT "|8."

LOOP

thank in advance

Posted: Fri Aug 03, 2007 10:28 pm
by Stoves
TIMER returns the number of seconds that have passed since midnight. Precision is to the hundredths of a second.

The following code sets the timer to 5.5 seconds and then prints a notice when the timer expires.

Code: Select all

DIM TimeToExpire AS DOUBLE
DIM SecondsToWait AS DOUBLE

SecondsToWait = 5.5

PRINT "Timer started..."
TimeToExpire = TIMER + SecondsToWait
DO
LOOP UNTIL TIMER >= TimeToExpire
PRINT "Time's Up! " + LTRIM$(RTRIM$(STR$(SecondsToWait))) +" seconds have passed."

Posted: Fri Aug 03, 2007 11:34 pm
by Stoves
Here's your code revamped to use TIMER to move the enemy after a set amount of time. Change the whenToMoveEnemy variable to anything .01 seconds or more to set the time between enemy movements.

You'll notice there was a need to add another timer-related variable to make this work right. The first variable (startTime) is set only once so that the total timer displays correctly. The oldTime variable resets to TIMER whenever the enemy moves.

Code: Select all

DIM startTime AS INTEGER
DIM x AS INTEGER, y AS INTEGER
DIM enemyx AS INTEGER, enemyy AS INTEGER
DIM whenToMoveEnemy AS DOUBLE
DIM oldtime AS DOUBLE

whenToMoveEnemy = 3
x = 3 
y = 7 
enemyx = 20 
enemyy = 18 
startTime = TIMER 

DO 
LOCATE 1,1
PRINT "TIME: "; INT(TIMER - startTime)

LOCATE y, x 
PRINT ".8." 

IF (TIMER - oldtime) >= whenToMoveEnemy THEN 
  locate enemyy, enemyx 
  PRINT "   "
  enemyx = enemyx - 1
  IF enemyx < 1 then enemyx = 40
  locate enemyy, enemyx
  PRINT "|8." 
  oldTime = TIMER
END IF

LOOP