01-07-2023, 05:12 AM
(This post was last modified: 01-07-2023, 05:22 AM by fistfullofnails.
Edit Reason: Code printed twice
)
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.
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.
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
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.