Qbasicnews.com

Full Version: RND problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hey everyone, I'm new...

So, I'm in a computer class and we have a project that involves making holiday scenes. Mines comining along fine except I want some lights that flash using a RND command but I only get two colors (blue and black) Any solution? The section of code for this is below (haven't gotten to the flashing part yet...).

Code:
SUB lightsonhouse

FOR c = 60 TO 240 STEP 20
CIRCLE (c, 220), 5, 0
PAINT (c, 220), RND, 0
RANDOMIZE TIMER
NEXT c

END SUB
RND command get's a number from 0 to 1


that includes decimals
so what you have to do is

Code:
INT(RND * 5) + 1

that from 1 to 5
Thanks, but I have another question about making it flash.

I have a GOTO statement so it just repeats the code to make the lights flash, but the lights just keep flashing...forever. Anyway around it?

Code:
SUB lightsonhouse

10 FOR c = 60 TO 240 STEP 20
CIRCLE (c, 220), 5, 0
PAINT (c, 220), INT(RND * 10) + 1, 0
RANDOMIZE TIMER
NEXT c
SLEEP 1
GOTO 10

END SUB
I recomend you use DO LOOP

but it needs and exit condition.

What's the SLEEP for?
DO LOOP? sorry, never heard of it. You mind explaining it (my help files don't work so I can't just look it up...), or at least point me toward a tutorial for it.

And the SLEEP is so theres a pause for the lights so it looks like lights flashing.

Nevermind, looked at the tutorial on the main site. But one more question hopefully. How do I make it so the lights keep flashing as the rest of my program runs. It just repeats the lights right now.
sorry, ive got a question.

What does the sleep command do and how do you use it?
Sleep pause program execution for a period of time you pass to SLEEP as an argument.
ie:
SLEEP 10 will pause the program for 10 seconds
DO
PRINT "YO!"
SLEEP 10
LOOP

This'll print "YO!" every 10 seconds... ALSO, if you press a key it cancels the SLEEP. So, you can also just say

Code:
SLEEP
instead of
Code:
DO
LOOP WHILE INKEY$ = ""
Although, thats bad coding practice, because SLEEP doesent clear the keyboard buffer, so your computer may start beeping after a few keystrokes.
Pages: 1 2