Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
RND problem
#1
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
Reply
#2
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
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#3
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
Reply
#4
I recomend you use DO LOOP

but it needs and exit condition.

What's the SLEEP for?
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#5
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.
Reply
#6
http://qbasicnews.com/qboho/qckdo.shtml
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#7
sorry, ive got a question.

What does the sleep command do and how do you use it?
Reply
#8
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
his sig left intentionally blank
Reply
#9
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$ = ""
Reply
#10
Although, thats bad coding practice, because SLEEP doesent clear the keyboard buffer, so your computer may start beeping after a few keystrokes.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)