|
Post by rosy on Aug 30, 2021 9:59:47 GMT -6
WindowOpen(0, "maximize", WINDOWPOS_CENTERED, WINDOWPOS_CENTERED, 640, 400, WINDOW_RESIZABLE, 1)
CanvasOpen(0, 640, 400, 0, 0, 640, 400, 1)
poz=1
Do
s=inkey
Update
If s=K_Space then
'SetWindowFullscreen (0, 1-WindowIsFullscreen(0))
print poz;" full ";s
poz=poz+1 wait(1000)
End If
Loop
Why does 1 press of the spacebar make 2 invocations? And after putting it into the game's loops, it sometimes causes IF to infinity, and it happened also once that the POZ variable was reset, I don't know the man.
|
|
|
Post by J7M on Aug 30, 2021 13:18:39 GMT -6
Your program shows on my computer the same thing. Interestingly, I never used inkey so far. When replacing your if statement with "if key(K_SPACE) then" and removing inkey, the programs seems to work fine.
|
|
|
Post by rosy on Aug 30, 2021 14:14:23 GMT -6
If you move UPDATE to the end, it's OK too.
|
|
|
Post by johnno56 on Aug 30, 2021 14:50:08 GMT -6
Two invocations? There is a word I have not heard in a long time... Cool.
The reason may be that you are using 'inkey' to scan the entire keyboard for a key press AND scanning specifically the space key for a key press.
Therefore if space is pressed then 'k_space' AND 's' registers a press each...
Good point about the positioning of update(). A "rule of thumb" that I use is, when creating a 'game loop', my first line is generally a clearcanvas (or other screen clearing process) and the last line is update()... That is 'my' habit... I would be curious to know if anyone has come up with another 'habit'...
It is almost 0650 and my first coffee for the day has already happened... looking forward to the next...
Have a great day, guys.
J
|
|
|
Post by rosy on Aug 31, 2021 3:40:29 GMT -6
I'm not scanning SPACE, but checking the value of S. But maybe you guided me to an explanation ... It is possible that the actual keyboard reading occurs at the UPDATE moment, the keys are dumped into the buffer, from which the KEY or INKEY function reads. If we want to read exactly (well ... after vsync) at the moment we should call INKEY right after UPDATE. In my example, the opposite is true. The key is read from buffer and UPDATE immediately puts another character into the buffer, before the buffer is updated with another UPDATE (when we are not pressing anything) the INKEY function will download it again. And only then there is another update of the buffer (clearing when we do not press anything).
It is a pity that such things are not explained in the manual, as a result we have hours of frustration before we guess or not ...
|
|
|
Post by johnno56 on Aug 31, 2021 14:40:52 GMT -6
Ah... The Manual... SDLBasic has a similar problem with their manual. Sure, the commands and descriptions are all there, but there are only a few examples of code. This is because SDLBasic dev team hovers between one and none. It's been that way since at least 2007. RCBasic has a dev team of one. The manual is an important part of any computer language but is also a part of the language that initially requires a 'lot' of time and effort to create and then time and effort to maintain.
The solution is simple... We need a larger community. From those we can assign tasks, like updating the manual... Well... may by 'not' so simple but you get the idea. One developer can only do so much (sorry n00b... not a reflection on your abilities but pointing out how much time you can dedicate to 'all' aspects of RC).
For the rest of us... Unless we are hiding our skills as 'Document Writers'... Time consumption and frustration are something we may have to endure... *sigh*
|
|