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?
#5
Hi again,

When an event occurs we need to handle it (do something) - in your code you do it directly in the event subroutine 'test'.  This is OK, but sometimes this can cause problems (mainly because the event happens on a separate thread) and then it may be better the create a repeating loop (called game or event loop) that keeps looping and checks on a variable set in the event subroutine (we call this variable a flag).  This is the essense of the nice sample Nonki shared and the comments by AB about event subroutine being short.  AB is also correct that the event subroutine only needs to be set once.  For more information on this see the links below.

https://learn.microsoft.com/en-us/archiv...ent-basics
https://learn.microsoft.com/en-us/archiv...c-graphics
https://learn.microsoft.com/en-us/archive/technet-wiki/22264.small-basic-threading

Without refactoring your code a lot, we need to wait after T0 is set until a key is pressed.  The code below is one way we could do this.

Code:
  T0 = Clock.ElapsedMilliseconds
  frappe = ""
  While (frappe = "")
  EndWhile
[-] The following 3 users Like litdev's post:
  • AbsoluteBeginner, Elzaimer, 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-24-2024, 02:49 PM

Forum Jump:


Users browsing this thread: 6 Guest(s)