<< Previous Topic | Next Topic >>Return to Index  

Coding help

March 6 2017 at 10:16 AM
MJ  (Login Mongojerry_2)

 
So I am trying to create a simple program to time some random events. Essentially I want the system to send printed responses to the screen display.

Step 1: Downtime--pause for 10-120 seconds. Display "Downtime [time]." Proceed to Step 2.
Step 2: 2% chance of displaying "On [120 seconds]." Return to step 1. Else proceed to Step 3.
Step 3: Determine a random time from 3-20 seconds and display "On [time]." After pause, return to Step 1.

I've created a program to do this but it's not working--I believe I am using several commands incorrectly. I would really appreciate any help correcting the syntax of this!

DOWNTIME:
TIMER ON
LET X = INT(RND * 100 + 10)
BEEP
PRINT "Downtime "; X
ON TIMER(X) GOSUB STEP 2

STEP2:
IF RND * 100 <2 THEN
PRINT "Win"
BEEP
TIMER ON
ON TIMER(120) GOSUB DOWNTIME
ELSE GOSUB STEP3

STEP3:
TIMER ON
LET X = INT(RND * 17 + 3)
BEEP
PRINT "Active "; X
ON TIMER(X) GOSUB DOWNTIME


 
 Respond to this message   
AuthorReply
MJ
(Login Mongojerry_2)

Progress

March 6 2017, 11:07 AM 

Fixed most of this to work as planned except the time delays. Any help on how to structure the TIMER command would be appreciated!

 
 Respond to this message   
mn
(no login)

have you been to the wiki?

March 6 2017, 11:14 AM 

http://www.qb64.net/wiki/index.php/ON_TIMER(n)

 
 Respond to this message   
MJ
(Login Mongojerry_2)

Thanks!

March 6 2017, 12:01 PM 

Thanks--that was super helpful!

Added a Sleep command to the code so now the delay is working. Only remaining problem is that the delay is too short. When the value of X is, say, 90, ON TIMER(X) flips over in closer to 20 seconds. Any experience with that?

 
 Respond to this message   
mn
(no login)

that one you might want to ask on the qb64 forum...

March 6 2017, 1:15 PM 

i never used on timer, or any events that i could avoid. i always checked the value of the timer function instead.

 
 Respond to this message   
MJ
(Login Mongojerry_2)

Working now

March 6 2017, 1:50 PM 

Thanks for your help--sending me to the Wiki was fantastic. I have the program working exactly as I want it now. So happy with it. I dropped the "ON TIMER" commands entirely and just used the SLEEP command with a timed parameter.

Thanks, again!

MJ

 
 Respond to this message   
mn
(no login)

* cool! youre welcome

March 6 2017, 2:34 PM 


 
 Respond to this message   
-
(no login)

BEEN TRYING TO REACH YOU

March 16 2017, 1:39 PM 


 
 Respond to this message   
 
  << Previous Topic | Next Topic >>Return to Index  
 Copyright © 1999-2017 Network54. All rights reserved.   Terms of Use   Privacy Statement