psychopy.org | Reference | Downloads | Github

Name 'trials' is not defined

MacOS Catalina
PsychoPy 2020.1.2

Hello!

I am running into an issue setting up practice trials. In the first routine of my practice trials loop, I insert a code component and, in the BeginExperiment tab, I declare 2 variables as so:

total_acc = 0
total_num = 0

The total_num variable represents the total number of trials completed in the practice loop (there are two practice blocks, and the participant must go through both), and the total_acc is the trials with correct responses.

At the end of the practice loop, I have a feedback routine, still within the outer practice trials loop, with text feedback for a participant if they do not achieve a certain accuracy. I then set the nReps of the outer practice loop to something like 99, and break the loop only if the participant reaches a certain accuracy threshold. I inserted a code component, this time in the BeginRoutine tab of a code component in the feedback routine:

if(total_num == 50 and total_acc < 20):
    skipThisTrial = False
    continueRoutine = True
    total_acc = 0
    total_num = 0
elif(total_num == 50 and total_acc >= 20):
    trials.finished = True
    skipThisTrial = True
    continueRountine = False
else:
    skipThisTrial = True
    continueRoutine = False

The problem I face is that I get an error message as shown below:
image
Just to clarify, I have an outer practiceLoop, then 2 loops for each block (i.e. block1Loop and block2Loop), and within those loops there is also a trialSequence loop. I understand I cannot end an outer loop from within an inner loop, however the above code is located only within the outermost practiceLoop.

Any ideas or suggestions about what may be going wrong here?

Thank you!
Daniel

Your code looks like Python not JavaScript.

Locally (and therefore in Python) you need to refer to the loops by their names. Online (and therefore in JavaScript) you have to refer to all loops as trials.

Sorry for the confusion… here is the equivalent JS code:

if (((total_num === 50) && (total_acc < 20))) {
    skipThisTrial = false;
    continueRoutine = true;
    total_acc = 0;
    total_num = 0;
} else {
    if (((total_num === 50) && (total_acc >= 20))) {
        trials.finished = true;
        skipThisTrial = true;
        continueRountine = false;
    } else {
        skipThisTrial = true;
        continueRoutine = false;
    }
}

I just wrote it in Python and used the auto-translate feature.

If I understand your answer correctly, does that mean I must create and debug my experiment locally with Python, and then once I port it to Pavlovia, translate the code to JavaScript and modify any relevant code, such as this case?

Thank you!

I don’t know about “must” but I’m certainly taking the approach of making an experiment run in both environments. If something doesn’t work online, then does it work locally? if not, then the issue may be nothing to do with Pavlovia or JavaScript.

Have you spotted this spelling error?