Disabling moving on to next trial if task is not finished

Hi!
I’m building an experiment where subjects will perform a drag-drop task for 4 stimuli. So far the experiment works alright, but I want to make sure that they place all 4 stimuli before they can skip to the next trial.
How can I make sure that they can’t move forward to the next trial if they haven’t placed all stimuli?
I’m attaching the experiment as well as screenshots of my routine and the code I used.
p.s. there are no right or wrong answers in the experiment, but there are 8 possible locations where the stimuli can be placed.
Thanks in advance!
FS2-A.psyexp (236.2 KB)


image
image

Hi @Betul_O, this can be done by setting the “start” field of the keyboard component that ends the routine to “condition” and specifying a condition that has to be satisfied before the respondent should be able to end the routine.

The condition, of course, depends on your experiment. When exactly should your participants be able to end the routine?

Hi Ajus, thanks for your quick response!
To end the routine, participants must place each of the four stimuli (pictures) into a desired location on the screen. They have 8 options in which they can choose, so there are no right or wrong answers. After that they press the space key to proceed to the next one. I want to make sure they place all stimuli before moving on to the next trial.
However, I have no idea how I can specify the condition since there is no set location for any of the stimuli. If the condition is made to be clicked and dragged, it won’t guarantee that the stimuli is dragged into one of the 8 possible locations. They may just click and leave it on a neutral space, which is unwanted. Somehow I should set the condition so that all 4 stimuli are put in one of the possible locations.
If that one is not possible, I guess setting a condition so that all stimuli should at least be clicked and dragged can suffice but I don’t know how to do that either :confused:

In this scenario, you could check whether each of the images is inside a polygon (I suspect that these are the locations that the images should be dragged to, right?).

Each frame

match = [] # create empty list

for img_position in [P1.pos, P2.pos, P3.pos, P4.pos] # for each image
    for polygon in [S1, S2, S3, S4, S5, S6, S7, S8]: # and each polygon
        if polygon.contains(img_positon): # check whether this polygon contains this image
            match.append(1) # if so, add a 1 to the list

allow_continue = len(match) == 4 # allow respondents to continue if there are 4 1's in the list



Hope that does what you need!

1 Like

Thank you so much! Sorry for being such a bother but I have one more question :pray: I can’t seem to get the key_resp condition right. Some of the ones I tried are below. None worked and I have no idea what else I can try.
$allow_continue = len(match) == 4
$len(match) == 4
$len(key_resp.keys)==4
$allow_continue
$allow_continue = len(match) == 4
$allow_continue==4
$mouse.isPressedIn==4
$mouse.isPressedIn(piece)==4

$allow_continue should work, if it doesn’t then there might be something wrong with my code. Could you send me your complete experiment so I could debug this?

$allow_continue gives the following error:

File “D:\TEZ\FS2\FS2-A - Copy_lastrun.py”, line 1093, in
if key_resp.status == NOT_STARTED and allow_continue:
NameError: name ‘allow_continue’ is not defined

Experiment ended.

The code gave a syntax error at first because of a spelling error and a lack of “:” but worked alright after I added them. I’m attaching my experiment but since I used images that you don’t have, the experiment won’t run. Should I change the images into polygons so that it runs on your computer? If so, I’d need to change the code too I guess and I’m afraid to mess it up further.
Again, thank you so much for taking your time to help me :pray:
FS2-A.psyexp (236.7 KB)

Maybe it helps to add allow_continue = False to Begin routine, just to make sure that the variable is defined before the condition is checked for the first time.

No need to apologize, by the way. If it wasn’t fun for me to help people figure something out I wouldn’t frequent this forum :smiley:

It worked! I’m so happy, thank you very much :partying_face:

One caveat: With this solution, participants could still finish the routine if they dragged all images into the right locations once but removed one or more images again afterward. If the condition is met once, participants are able to continue regardless of what’s the final state of the images.

To change that, you could set your keyboard component to be started at time 0 and uncheck “force end routine”. Then add after the previous code

Each frame

keys = key_resp.getKeys()

if "space" in keys and allow_continue:
    continueRoutine = False

I think that’s not going to be a problem because I doubt they will re-drag the images to a neutral zone after taking the time to place them. However, it’s better to be safe so thank you very much!