06-24-2024, 02:49 PM
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.
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