while: wend
#22
Ok, SMcneill's example program definitely helped me see what is happening, and Terry's explanation helped to solidify the point.  I thank y'all very much.  So what I've generally tend to do through Terry's tutorials, is to make up my own little programs using some of the things I've just read about.  I was going to post this in a separate place, but I'm thinking it might be appropriate being as I think the problem might lie in the buffer situation being discussed.  I attempted to make a model of a traffic light.  I realize it's pretty rough and I know I could shorten it using some more variables and loops, but I just wanted to get something working to start with.  So don't make too much fun haha.

Code: (Select All)
CONST SCREENWIDTH = 900
CONST SCREENHEIGHT = 900
CONST RED = _RGB32(80, 0, 0)
CONST YELLOW = _RGB32(80, 80, 0)
CONST GREEN = _RGB32(0, 80, 0)
CONST BRIGHTRED = _RGB32(255, 0, 0)
CONST BRIGHTYELLOW = _RGB32(255, 255, 0)
CONST BRIGHTGREEN = _RGB32(0, 255, 0)
CONST DULLYELLOW = _RGB32(40, 40, 0)
DIM x%
DIM Keypress$



x% = SCREENWIDTH / 2
CONST WHITE = _RGB32(255, 255, 255)
SCREEN _NEWIMAGE(SCREENWIDTH, SCREENHEIGHT, 32)


DO
    Keypress$ = INKEY$
    CLS
    _LIMIT 30
    LINE (300, 200)-(600, 700), DULLYELLOW, BF
    'Red
    CIRCLE (x%, 300), 50, WHITE
    PAINT (x%, 300), BRIGHTRED, WHITE
    CIRCLE (x%, 450), 50, WHITE
    PAINT (x%, 450), YELLOW, WHITE
    CIRCLE (x%, 600), 50, WHITE
    PAINT (x%, 600), GREEN, WHITE
    SLEEP 8
    'Green
    CIRCLE (x%, 300), 50, WHITE
    PAINT (x%, 300), RED, WHITE
    CIRCLE (x%, 450), 50, WHITE
    PAINT (x%, 450), YELLOW, WHITE
    CIRCLE (x%, 600), 50, WHITE
    PAINT (x%, 600), BRIGHTGREEN, WHITE
    SLEEP 8
    'Yellow
    CIRCLE (x%, 300), 50, WHITE
    PAINT (x%, 300), RED, WHITE
    CIRCLE (x%, 450), 50, WHITE
    PAINT (x%, 450), BRIGHTYELLOW, WHITE
    CIRCLE (x%, 600), 50, WHITE
    PAINT (x%, 600), GREEN, WHITE
    SLEEP 5

LOOP UNTIL Keypress$ = CHR$(27)
SYSTEM


CONST SCREENWIDTH = 900
CONST SCREENHEIGHT = 900
CONST RED = _RGB32(80, 0, 0)
CONST YELLOW = _RGB32(80, 80, 0)
CONST GREEN = _RGB32(0, 80, 0)
CONST BRIGHTRED = _RGB32(255, 0, 0)
CONST BRIGHTYELLOW = _RGB32(255, 255, 0)
CONST BRIGHTGREEN = _RGB32(0, 255, 0)
CONST DULLYELLOW = _RGB32(40, 40, 0)
DIM x%
DIM Keypress$



x% = SCREENWIDTH / 2
CONST WHITE = _RGB32(255, 255, 255)
SCREEN _NEWIMAGE(SCREENWIDTH, SCREENHEIGHT, 32)


DO
    Keypress$ = INKEY$

    CLS
    _LIMIT 30
    LINE (300, 200)-(600, 700), DULLYELLOW, BF
    'Red
    CIRCLE (x%, 300), 50, WHITE
    PAINT (x%, 300), BRIGHTRED, WHITE
    CIRCLE (x%, 450), 50, WHITE
    PAINT (x%, 450), YELLOW, WHITE
    CIRCLE (x%, 600), 50, WHITE
    PAINT (x%, 600), GREEN, WHITE
    SLEEP 8
    'Green
    CIRCLE (x%, 300), 50, WHITE
    PAINT (x%, 300), RED, WHITE
    CIRCLE (x%, 450), 50, WHITE
    PAINT (x%, 450), YELLOW, WHITE
    CIRCLE (x%, 600), 50, WHITE
    PAINT (x%, 600), BRIGHTGREEN, WHITE
    SLEEP 8
    'Yellow
    CIRCLE (x%, 300), 50, WHITE
    PAINT (x%, 300), RED, WHITE
    CIRCLE (x%, 450), 50, WHITE
    PAINT (x%, 450), BRIGHTYELLOW, WHITE
    CIRCLE (x%, 600), 50, WHITE
    PAINT (x%, 600), GREEN, WHITE
    SLEEP 5

LOOP UNTIL Keypress$ = CHR$(27)
SYSTEM
I expected nothing to happen when pressing any key other than escape.  But what actually does happen, is that it seems to jump to the next piece of code after the nearest 'sleep' command.  Maybe I should be using '_delay' instead?  Even when I press 'ESC', it does the same thing, but eventually does exit now and then. I do not know why the code is duplicated here after the first time. Sorry. Also, I had the '_display' command in that code right near the end. But my traffic light always froze after one time through the loop until I removed that command.

Second edit: I have sort of answered my own question about the 'sleep' and '_delay' commands. After reading up on them in the keyword reference guide for QB64, I think it's saying that by pressing any button during the sleep "pause", that it will move on. So I changed all _delays to sleep, and now random button presses seem not to interfere with the timing. I still have the problem of not being able to exit the loop after pressing 'ESC' though.
Reply


Messages In This Thread
while: wend - by fistfullofnails - 01-03-2023, 06:09 AM
RE: while: wend - by SMcNeill - 01-03-2023, 06:28 AM
RE: while: wend - by mnrvovrfc - 01-03-2023, 07:56 AM
RE: while: wend - by bplus - 01-03-2023, 03:39 PM
RE: while: wend - by mnrvovrfc - 01-03-2023, 07:54 PM
RE: while: wend - by bplus - 01-03-2023, 03:57 PM
RE: while: wend - by james2464 - 01-03-2023, 04:07 PM
RE: while: wend - by fistfullofnails - 01-05-2023, 07:36 AM
RE: while: wend - by SMcNeill - 01-05-2023, 08:38 AM
RE: while: wend - by Kernelpanic - 01-03-2023, 08:40 PM
RE: while: wend - by TempodiBasic - 01-04-2023, 12:13 AM
RE: while: wend - by bplus - 01-04-2023, 01:09 AM
RE: while: wend - by bplus - 01-04-2023, 01:55 AM
RE: while: wend - by SMcNeill - 01-04-2023, 02:52 AM
RE: while: wend - by bplus - 01-04-2023, 04:12 AM
RE: while: wend - by mnrvovrfc - 01-04-2023, 04:51 AM
RE: while: wend - by bplus - 01-04-2023, 05:22 PM
RE: while: wend - by Kernelpanic - 01-05-2023, 12:26 PM
RE: while: wend - by TerryRitchie - 01-05-2023, 04:55 PM
RE: while: wend - by TempodiBasic - 01-05-2023, 06:36 PM
RE: while: wend - by TerryRitchie - 01-05-2023, 11:04 PM
RE: while: wend - by fistfullofnails - 01-07-2023, 05:12 AM
RE: while: wend - by SMcNeill - 01-07-2023, 06:51 AM
RE: while: wend - by mnrvovrfc - 01-07-2023, 06:29 AM
RE: while: wend - by OldMoses - 01-07-2023, 01:55 PM



Users browsing this thread: 7 Guest(s)