psychopy.org | Reference | Downloads | Github

Matching pennies games

OS (e.g. Win10): OS Sierra, 10.13.6

PsychoPy version (e.g. 1.84.x): v2021.1.2

Standard Standalone? (y/n) y If not then what?:

What are you trying to achieve?:

Hi all,

First of all thank you for creating this space for Q&A, it is really helpful for newbie in PsychoPy like me.

My current problem is the following:

I am building a matching pennies game, based on this github: tomsup/tutorials/psychopy_experiment at master · KennethEnevoldsen/tomsup · GitHub

In this task, participants have to guess in which hand the virtual agent has hidden a coin.
I have been able to successfully implement the task in the Coder and adapted it using cards instead of hands and it is running smoothly locally.

However, I would like to run this task through Pavlovia, so I am building the same task right now using Builder.

I was able to create virtual agents based on excel files with different level of bias and provide feedback about the outcomes of each trial (e.g., you choose left, the virtual agent choose right).

But I am struggling to add visuals corresponding to participant’s choices and agent’s choices.

For example, when the participant choose the left card, I would like to display the appropriate visual (e.g.,


and then provide the final visual depending of the virtual agent’s choice (e.g., either or ).

I have scrolled across different topics and tried different solutions but I am struggling to translate the Python code into Builder components.

The original code is the following for the participant’s choice:

if k[0] == “left”:
picture1 = visual.ImageStim(
win, image=Choice_B, units=“norm”
)

elif k[0] == "right":
    picture1 = visual.ImageStim(
        win, image=Choice_R, units="norm"
    )

And here is the code for the virtual agent’s response:

if rl_tom == “left” and k[0] == “left”:
picture1 = visual.ImageStim(
win, image=Win_B, units=“norm”
)

elif rl_tom == "left" and k[0] == "right":
    picture1 = visual.ImageStim(
        win, image=Loose_R, units="norm"
    )

elif rl_tom == "right" and k[0] == "left":
    picture1 = visual.ImageStim(
        win, image=Loose_B, units="norm"
    )

elif rl_tom == "right" and k[0] == "right":
    picture1 = visual.ImageStim(
        win, image=Win_R, units="norm"
    )

I tried adding a code component for the participant’s choice:

Begin Experiment:
Choice_B = “images/Choice-Blue.png”
Choice_R = “images/Choice-Red.png”

Begin Routine:
if key_resp_2.keys == ‘left’:
picture1 = Choice_B
else:
picture2 = Choice_R

With 2 images components picture1 and picture2 but it didn’t work.

The error I got is AttributeError: ‘str’ object has no attribute ‘tStart’

Any hint about how to solve this problem?

Let me know if you need more info about the way the Builder is configured right now.

Thank you very much for your help.

I think what’s happening is that your Begin Routine code isn’t setting the value of the picture - it’s replacing the Image object altogether with the string value you’re trying to set. Rather than picture1 = Choice_B it should be picture1.image = Choice_B, for example.

Hi @TParsons,

Thank you very much, it’s working perfectly fine now :slight_smile: