Need help with a couple tasks

Hi guys! I need help with a couple tasks since i’ve been struggling a bit. Would much appreciate your guidance <3

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2.6
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?: I’m trying to adapt some tasks for a virtual environment. It’s been going well, but right now i’ve come to a problem.
Most of my tasks involve something simple: there is a model to the left and the participant must match one of the options (1, 2, 3 or 4) with the model using some rules (eg. in a task they need to answer which line option is oriented in the same direction as the model).

Thing is, in some of them i need not only a feedback mechanism, but i need to make an example task. Basically i need to it in a way that the first 2 items have this mechanism:

If you get it right, advance to the next one;
If you get it wrong, get back to try again.

Basically, as long as the participant gets it wrong, it goes back to itself, but as soon as they get it right, they advance.

What did you try to make it work?:
Up until now i figured out a way to present the feedback, but can’t quite make it so that when the answer is wrong, it’ll come back to the same item.

This is what came up with:

On the “Begin Experiment” session of the code, there is this:

Then, at the “End Routine”, there is this:

if key_resp_RM_exemplo.corr:#stored on last run routine
    RM_ex_loop.finished = True
    msg="Oops! That was wrong"

It seems to work, but i’m still stuck on the “get back to it when they get it wrong” part.

OS (e.g. Win10): Win10
PsychoPy version (e.g. 1.84.x): 2.6
Standard Standalone? (y/n) If not then what?:
What are you trying to achieve?: Also, i need help on something else. One of the tasks mental construction. The model to the left is a square composed of 4 geometrical figures. To the right, the 4 options are the same geometrical figure, this time separated. IRL i’ll ask the particpant: “On which sides do figures 1 and 2 touch eachother on the model?”. The participant must then touch their finger on the side of the geometrical figure they believe is the right one. It’s kinda hard to explain without showing it, but the point is: i need a way to let the participant select the side of the geometrical figure they think is the right one (with a visual feedback that they selected it, like it’s marked), and when they’re done selecting, they can click a button to finish the task. I don’t know if this is comprehensible, and if you need more info i’ll try my best to provide it.

What did you try to make it work?:
I tried to use the Brush response. It KINDA works, but not only would it be better if they could just click once to select a side of the figure, but it would make it much easier to interpret the data later.

Also, using the Brush response, it only registered the coords where the mouse started being pressed and stopped being pressed (only 2 coords, basically), which is not enough to ensure which spot they marked.

Thank you very much in advance, i really need some help here :slight_smile:

For #1:

I’m assuming NLoop = 20 is your number of trials, correct? And you put that in nReps for the number of loops? Then you have all of your conditions for each of the 20 trials set up ahead of time and call to your trials’ conditions with currentTrialCondition = conditions[NLoop], correct?

If so, you’re going to want to take NLoop out on nReps for your loop and instead set nReps to a really high number like 999999 or something. Then set nTrials = 20 (number of trials they need to get correct) and trial = 0 (current trial #) at the beginning of the experiment. Then in your loop, set up your conditions like currentTrialCondition = conditions[trial]. Then at the end of your loop, make a routine with a code component:

if key_resp_RM_exemplo.corr:#stored on last run routine
    trial = trial + 1 #to go to next trial
    msg="Oops! That was wrong"
    #don't update trial if they were wrong so it calls to the same conditions in the next trial as in the previous trial

if trial == nTrials: #if you've reached the last trial, end the loop
    loop.finished = True

So now it will only exit your loop if they’ve gotten 20 trials correct.

For #2:

I can’t help as much here, but maybe try to make your shapes out of polygon components (one for each side) and then make them like buttons when you click on them? That’s probably a pain, but that’s all I can really think of.

Thank you very much, sal!

You helped me a lot. Thing is, i can’t quite get what you mean when you say

Sounds like something i still need to code. This is what i have on my excel file:

I think my issue is that i need a variable that tells my program to only go to condition 2 when the participant get the right answer on condition 1. And if i’m correct, you’re asking if i have a variable for that. The answer is no…

What i had before i tried your code is as follows:

Where the loop uses the excel file to get the variables as 2 parameters (ITENSBVARMexemplo and RESPOSTARMexemplo) and both conditions (also 2).

The first routine are images and correct responses which are loaded as variables (set every repeat).

There’s a code for a feedback function on the other routine.

What i need to know is how to use a code like the one you showed me while also making sure this happens:

  1. Participant sees Task 1 (condition 1, AKA imagens/RMA.jpg). If they put the wrong answer, they’re back to Task 1 until they get it right.

  2. When they get it right, the program advances to Task 2 (condition 2, AKA imagens/RMB.jpg. If they put the wrong answer, they’re back to Task 2.

What usually happens is that the first part works wonders, but when they get Task 2 wrong, it goes back to Task 1.

(unfortunately i can’t load more images on this post as an example since my account is new)

I was able to “SOLVE” this issue by making separate loops, one for the first condition (imagens/RMA.jpg) and onde for the second one (imagens/RMB.jpg).

Then, i made RM_Ex1 and RM_Ex2 which are routines for the images + keyboard answer, but now as a constant instead of $ITENSBVARMexemplo.

I also made 2 new routines for the code you posted, code_RM_exemplo1 and code_RM_exemplo2. That made it work, but now i have 2 loops instead of one.

Also, the loops are set to 9999 repetitions and no conditions.

But as you can imagine, it’s not automated enough. I know it’s possible to do it like i want to (one loop, both conditions) i just can’t quite get it right.

Am i being able to specify my issue? If not, please let me know, i’ll try my best.

Also, thank you again!

It’s not just the two rows in your excel, right? I was assuming you had 20 trials for the experiment because of your variable NLoops=20 you wrote in the post. But I’m going with two for now because the code is the same regardless. currentTrialCondition = conditions[NLoop] is how you were going to call to the conditions for each task, which I was assuming you were already doing.

Key for my explanation:
column1 is the image variable (I’m assuming you already read the columns into their own array variables)
column2 is the number variable in your second column (ditto ^)
currentImage is the image you’ll call to for each task (so an entry from column1)
currentNum is the number you’ll call to for each task (entry from column2)
row is the row/entry in your two columns
numRows is the number of rows you actually have in the excel
responseAccuracy is whether or not they got the answer correct (1 is correct, 0 is incorrect)
loopTrial is your loop
msg is your message to the participant

In a code component at the beginning of the loop:
Before experiment:

#call in excel variables and such
row = 0 #0 is the first entry, 1 is the second
numRows = len(column1) #or 2 if it's always 2

Begin routine:

currentImage = column1[row] #grabbing the image from column 1 and whichever row you're on for the current task
currentNum = column2[row]

Then in a code component at the end of the loop after you show the images and get responses:
Begin routine:

if responseAccuracy == 1 : #if they were correct
    row = row+1 #so now in the first code, it will call the entries from the second row instead of the first (task 2)
    msg = "Correct!"
else : #if they were incorrect
    msg = "Incorrect"
    #don't update row so that the next loop is reusing information from the current row

if row == numRows : #if we're on the last row of the excel file
    loopTrial.finished = True #end the loop because they're done

I hope that makes sense…

Sal this sounds dumb, but i don’t know if i’ve done this already. I’m assuming i didn’t, since i don’t know.

The only time i loaded the file to be read by the experiment was from the loop window:

Are you asking if i made a code to load those variables? If so, no…this is basically my frist time coding, so i don’t know some pretty basic stuff.

Also, it seems like there are too few trials 'cause this is only a small part of a subtest from a bigger battery of tests. On 4 of the subtests the participant must answer an example before starting the test, and if they get it wrong, they have to try again until they’re familiar with this type of task. That’s why i need this code and that’s why it’s only 2 conditions. This is only one example from one of the subtests.

I made most of the battery already, but came into those examples and got stuck.

Thank you again for you time and patience, it’s been helping me A LOT.

I guess I just call in my conditions differently. But regardless of how you call to them, the code I showed you will work.

Looks like i’m still doing something wrong, 'cause it didn’t…

I tried using exacly like you posted, then i tried changing the variable names to the ones i’m using, but it does not seem to go back to Condition 2 when the participant gets Condition 1 right but Condition 2 wrong. It just goes back all the way to Condition 1.

The Row variable is working, tho. When i get Condition 1 right but Condition 2 wrong, it goes back to Condition 1. Then, if i get Condition 1 right again, the loop ends (since the code says that when i get it right, Row = Row +1 and when Row = 2, the loop ends).


I would tend to solve Problem 1 in this way:


A minimal working example is attached. The “task” is to press the key corresponding to the letter on the screen. If you get it wrong, the trial repeats. If you get it right, the inner loop ends, and the next iteration of the outer loop runs.


repeat_trials.psyexp (10.7 KB)
input.xlsx (8.5 KB)


It’s so simple and IT WORKED! Thank you so so much!!!

Also it makes a lot of sense now that i see it working. Well, the more you know!

Glad it worked. :slight_smile: I’m afraid Problem 2 is more complicated. You might want to create a separate topic for it if it remains unsolved. It might help to attempt to succinctly describe the problem in the title.


1 Like