psychopy.org | Reference | Downloads | Github

Loop stops after 40 trials every time

Description of the problem:
Objects Locations task, present one object one screen at a time;
I have the following learning criteria i’m trying to set -
if a participant places an object within 150 pix then its correct;
if they get an object correct twice in a row then it skips over this;
loop finishes when all objects placed correctly twice in a row;
Participants are given feedback each time.

I’ve included this as “online” because I had a version of it that worked but it never translated well with js.

this is what I have now as a code component:
Begin Exp:
obs_dict = {}

Begin Routine:

if obs_dict == {}:
    for image in trials.trialList:
        image = image['object']
        obs_dict[image] = 0
        

correct = False

xloc = trials.thisTrial['xloc']
yloc = trials.thisTrial['yloc']
image = trials.thisTrial['object']
if obs_dict[image] == 2:
    skipThisTrial = True  # variable to use in feedback etc
    continueRoutine = False  # end this routine
    if 0 not in obs_dict.values() and 1 not in obs_dict.values():
        # end the whole trials loop
        trials.finished = True
        
else:
    skipThisTrial = False

End Routine:

if mouse.x[0] in range(xloc-150, xloc+150):
    if mouse.y[0] in range(yloc-150, yloc+150):
        correct = True



if correct == True:
    obs_dict[image] +=1
elif correct == False and obs_dict[image] == 1:
    obs_dict[image] = 0

And in my feedback routine (Every frame):

if skipThisTrial:
    continueRoutine = False

here’s the builder structure:

and my conditions:

**i’ve tested that the obs_dict is updating as it should and getting correct/incorrect and these seem to work -
Key problem - the loop always stops after 40 trials (2 loops) whether correct or incorrect

This is the last step of my online study so if someone can get me over the line i’d massively appreciate it.

Cheers,
Tom

So just to be clear, is this something you’re having trouble with when you run it locally in Python, or when you try to run it on Pavlovia? All the code you’ve shared is the Python code, but if this is a problem with running online I would want to see the JavaScript code as well.

If it’s a problem running locally in Python, my guess is that something is setting trials.finished to True automatically after two loops. Without seeing the settings for the trial loop I can’t be sure.

thanks for getting back to me - i’ve just fixed it, i’ll post the solution in a bit when I get the chance just in case anyone else has a similar problem.

Cheers,
Tom

this worked locally - still need to get it online

begin exp:
obs_dict = {}

begin routine:

if obs_dict == {}:
    for image in trials.trialList:
        image = image['object']
        obs_dict[image] = 1
        


xloc = trials.thisTrial['xloc']
yloc = trials.thisTrial['yloc']
image = trials.thisTrial['object']

if obs_dict[image] == 2:
    print('skipping')
    if 0 not in obs_dict.values() and 1 not in obs_dict.values():
        # end the whole trials loop
        trials.finished = True
        
    skipThisTrial = True  # variable to use in feedback etc
    continueRoutine = False  # end this routine
else:
    skipThisTrial = False

End routine:

if skipThisTrial != True:
    if mouse.x[0] in range(xloc-150, xloc+150):
        if mouse.y[0] in range(yloc-150, yloc+150):
            correct = True
        else:
            correct = False
    else:
         correct = False
            
    if correct == True:
        obs_dict[image] +=1
    elif correct == False:
        obs_dict[image] = 0

then begin routine in the Feedback routine:

if skipThisTrial == True:
    continueRoutine = False