We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What command should I use to make my program pause until the user presses a key?
#15
Yea I tend to agree in general, however in this case I did't see any adverse effect (<1% cpu on my PC) and the code was about timing so introducing a Delay in the wait loop looked nasty (I also get the point that timing won't be that accurate anyway).  I didn't really want to open this tin of worms all in one go, I did leave some links to where it is discussed a bit more though.

Now we have openned the tin and see some of the issues, this is how I might refactor the program, MXJJ240.000

Note the silly long Delay on line 10 - clearly reduce to something that shows very low cpu in practice.

However, we can see that the Delay doesn't influence the timing because the timing is set within the event when it fires (maybe during a delay on UI thread).

I do all UI graphics updates on the main UI thread (not in an event thead - it will only do the UI update after the event thread is finished in an case and we cannot be sure exactly when it will actually happen if the main UI thread is also doing stuff).  This is the issue with the code I showed in post 13 and also probably why 'Program.Delay(2500) was commented in Elzamier's original code.

My reccomendation is to always use a game loop (with delay) and only use event subroutines to set flags that are handled predictably in sequence in the game loop.  Especially important for SB with its global variable scope.  Its hard to persude people of this without first going through some pain.

Interesting stuff and not just specific to Small Basic, understanding it here is fully transferable as is how it works under the hood in all window programs.
[-] The following 4 users Like litdev's post:
  • AbsoluteBeginner, Elzaimer, Scout, z-s
Reply


Messages In This Thread
RE: What command should I use to make my program pause until the user presses a key? - by litdev - 06-26-2024, 07:40 PM

Forum Jump:


Users browsing this thread: 3 Guest(s)