Ending trial after two conditions are met

Hello,

I am trying to end a trial when two conditions are met.

In the first instance: I am trying to end the trial when exactly one of my stimuli is clicked AND when the space bar is pressed. Having less than 1 stimuli selected and clicking space should continue the trial
Here is the code:




In the second instance: I am trying to end the trial when exactly three of my stimuli have been selected AND when the space bar is pressed. Having less than 3 stimuli selected and clicking space should continue the trial.
Here is the code:





This seems easy enough to code, but for some reason I am not able to continue to the next trial when the continueRoutine = False…

bump ^

The “continueRoutine = False” code needs to be in the “every frame” tab, because the “end routine” tab is only executed after the trial ends.

Thank you! I am still encountering some small issues:

In order for my code to work, I had to select the “force end routine” checkbox in the keyboard component; normally this shouldn’t be necessary if I am manually calling continueRoutine = False in my code?

I still have two small issues that I’m encountering. The first relates to the first type of trial (where only 1 response can be given by the participant).

In this code, there is a variable called “lastClicked” whose value updates “each frame” when a new stimulus is clicked. In the “end routine” section of the code, I call this variable in order to store the data as well as store whether the response was correct or not.

The first problem is that on the very first trial: if participants don’t select a response and press space to continue the trial, the experiment ends with the error message if lastClicked == C2corr: is undefined. This makes sense since the variable lastClicked only receives a value when a stimulus is clicked on. In order to combat this, I set lastClicked = 0 in the “begin routine” tab. I then tried to include a portion in the code which said if lastClicked is not equal to 0, then continueRoutine = False. So far this is not working.




The other issue is that for the second type of trials (three responses given by participant), if the space key is pressed when len(activeList) < 3 and then when the 3rd stimulus is clicked on, the trial ends immediately, so participants aren’t able to correct their answer if they would want to. I tried changing the keyboard component to store ‘first key / last key / all keys’ but this did not have any effect. Ideally, I would want the key press of ‘space’ to only count after all three stimuli are selected.

I think the issue is actually in including the ‘clicked’ condition to set continueroutine to false. All you should need is:

if endT1.keys == 'space' and lastClickedT1 != 0:
    continueRoutine = False