psychopy.org | Reference | Downloads | Github

Commanding Coder to print a stimuli from the excel sheet

I randomly show colorful circles in specific locations. I show a cue for the colorful circle and I want participants to remember the specific location. I get responses for the locations. If participant give an inaccurate response, I want PsychoPy to show the accurate response by showing the colorful circle in the accurate location.
Right now, I have a code like this:

“if mouse.isPressedIn(colourfulcircle):
testphase.finished = False
trials.finished=True
else:
testphase.finished = True”

Do you know how can I command Coder to show the accurate circle by reading it from the excel sheet?

Hi,

Sure, so if you have a header in your “conditions” excel sheet - say “corrLocation”, where the value is the xy coordinates of the correct location, your code component would look like

if mouse.isPressedIn(colourfulcircle):
    testphase.finished = False
    trials.finished=True
else:
    feedbackCircle.setPos(corrLocation)
    feedbackCircle.draw()
    win.flip()
    core.wait(feedbackDur)
    testphase.finished = True

Where feedbackCircle is a circle object you have created at the begining of the experiment and feedbackDur is the duration (in seconds) that you want your feedback circle to be presented for.

Is this intended for use as a code component in builderview? if so you want this component in the “End Routine” tab.

Hope this helps.
Becca

Thank you so much Becca. This helped me a lot! :slight_smile:

no problem!

Hello again Becca,

I have one more question: How can I count correct mouse responses? For example, I want loops (trials and testphase) to stop after 8 accurate responses. How can I adapt this to the code?

Hey,

There are multiple ways here. One would be to have a variable, say corrCount=0 specified in “begin experiment” and following a correct response you add to this as corrCount = corrCount+1 (in the first “if” part of the code above). Then when corrCount hits your limit (in your case 8) break the loop using the same method as before :blush:

Becca

Thank you for the quick response Becca. I tried your suggestion and it worked. There is one problem: I want counter to reset correct responses after the loop ends.

For example, in the test phase participants respond with mouse clicks but the loops trials and test should stop when participants give 8 accurate responses at one time.
Right now, correct responses are counted in test loop and if they give one incorrect answer trials loop starts again. Since the correct responses were counted before, the code continue to count from the number of previous trial.
I want to reset counts after test loop. How can I do this?

Hi!

Great it worked. to reset a variable you can always set it to be 0 again in the ‘end routine’ tab :slight_smile:

Thanks,
Becca

if mouse.isPressedIn(colourfulcircle):
corrCount=corrCount+1
if (corrCount >= 8):
test.finished=True
trials.finished=True
else:
whitecircle.draw()
colourfulcircle.setPos(corrLocation)
colourfulcircle.setColor(corrColor)
colourfulcircle.draw()
retrocue.draw()
win.flip()
core.wait(7)
test.finished=True
trials.started=True

Thank you Becca :slight_smile: But whenever I try to place “corrCount=0” somewhere, I get error.Where should I exactly add this to the code?

Although this question is tagged as “coding”, it seems from your screenshots that you are actually using Builder. In that case, you should purge any of your existing custom code of its win.flip() and core.wait() lines. These will break Builder’s careful timing, which relies on calling win.flip() itself on every screen refresh, typically 60 times per second.