Reputation: 1
I live in France and I'm new to programming.
I'm trying to code a test to assess the ability to concentrate (https://smallbasic.com/program/?RKCP997.000) but I'm encountering a problem. This is how it should work: A letter appears on the screen for 0.5 seconds then it disappears. You have to memorize it. Then 4 random letters appear and you must press as quickly as possible on the "Left" key if the original letter is absent and on the "Right" key if it is present.
So far my code works.
But this test should be repeated for 2 minutes, and at the end the number of errors and the average reaction time should be displayed. But when I make a loop (lines 13 and 38 in my program), the program loops without waiting for the user to press LEFT or RIGHT. What function should I use to make the program wait/pause until the user presses a key?
Thanks for your help ! :)
Upvotes: 0
Views: 102
Reputation: 19375
The programmed 10 loop cycles run too fast without delay, and thereafter the program ends. Rather what you want is a loop which runs for 2 minutes. But not in every loop cycle new test letters shall be drawn, only when the user pressed a key, so we need some flag or condition; we can use T1 for this purpose, which is set during the keypress handling. So we could use e. g.
Ts = Clock.ElapsedMilliseconds ' time of start
T1 = -1 ' indicate that a new test is to be drawn
while Clock.ElapsedMilliseconds < Ts+2*60*1000 ' until 2 min. later
if T1 <> 0 then
T1 = 0 ' no new test is to be drawn (until T1 set in sub test)
' here comes the code you already have for displaying the test
InitialNumber = Math.GetRandomNumber(26)+64
…
T0 = Clock.ElapsedMilliseconds
GraphicsWindow.KeyDown = test ' maybe move this before the loop
endif
Program.Delay(10) ' wait a bit
endwhile
A problem remains: The GraphicsWindow.Clear()
within the loop immediately erases the keypress result display - this is to be done somewhat differently.
Upvotes: 0