| Reference | Downloads | Github

Using the same condition to end one item and start another?



Does anyone know if it’s possible to use the same condition to stop one task and start another.

I have been able to stop a text task when press a key

and would like a new text box to begin at this point. If i post the same condition

event.getKeys(keyList=[‘1’, ‘2’, ‘3’]) as the start condition for a new text this doesn’t work.

Is it possible to have the same Condition simultaneously stop one text and start another?



This isn’t really a problem of the same “condition” not being able to be used twice, but that you are calling a function that gives a different result each time, which doesn’t really make it suitable to be regarded as a “condition”.

e.g. you call event.getKeys() and detect that a key has been pressed. You then call that function again: it won’t give a result unless a new key press event has occurred.

What you need to do is shift this code out of the conditions field and put it into a code component. In there, you will have code that runs every frame and checks for keypresses. If one of your desired keys is pressed, it sets some variable to True. You then use that variable name in your condition field. That way, it can be used multiple times, as the value of the variable remains constant. e.g. insert a code component and put this in the “begin routine” tab:

number_pressed = False # need an initial value

and then put something like this in the “Each frame” tab:

if event.getKeys(keyList=[‘1’, ‘2’, ‘3’]):
    number_pressed = True

and then put number_pressed in your conditions field. Make sure that the code component is above the other components, so they get access to the latest value of number_pressed on every frame.

Note that here although we are checking event.getKeys() repeatedly, it won’t reset the value of number_pressed to False when a keypress isn’t detected: if there is no keypress, nothing happens.

split this topic #3

3 posts were split to a new topic: Masked feedback from typing numbers