I want to build a Spot the difference trial. I tried to solve this by showing two pictures and on one picture i placed a circle over the differences like here: How to mark something during an experiment?
i don’t get anything in the outputfile. I Also tried:
if mouse.isPressedIn(difference_1)
addData(target1, True)
I generally don’t know how to save variables in the Code view, or how to tell psychopy to save data in the output file.
Do you have any examples?
And is it possible to Change the opacity of the circles when the participant klicks in it?
thanks for your answer, but the problem is still existing…
the participants should click on all differences.
i tried what you say, but there’s still no data in the outputfile (cvs or txt) and the oppacity isn’t changing when i click on the circles. i think the code element doesn’t place the code there where it should be…
Then in the preparation of the trial theres the code for pressing in the circle
if mouse.isPressedIn(difference_1):
foundtarget1 = 1
if mouse.isPressedIn(difference_2):
foundtarget2 = 1
if mouse.isPressedIn(difference_3):
foundtarget3 = 1
after that, the routine trial starts
after ending the routine, psychopy saves data in the ExperimentHandler
store data for thisExp (ExperimentHandler)
x, y = mouse.getPos()
buttons = mouse.getPressed()
thisExp.addData(‘mouse.x’, x)
thisExp.addData(‘mouse.y’, y)
thisExp.addData(‘mouse.leftButton’, buttons[0])
thisExp.addData(‘mouse.midButton’, buttons[1])
thisExp.addData(‘mouse.rightButton’, buttons[2]) thisExp.addData(‘Target_1’, foundtarget1) thisExp.addData(‘Target_2’, foundtarget2) thisExp.addData(‘Target_3’, foundtarget3)
thisExp.nextEntry()
it’s still not working… in the outputfile (txt) i can’t find a variable named “Target”
Hello Benjamin, as Richard suggests, you should re-format your code so that we can see if it is something as simple as an indentation error.
But my suspicion is that you have some of the code in the wrong tabs of the code component. If you want to check if a stimulus has been clicked, this really needs to be in the Each frame tab, so it gets checked on every screen refresh during the routine (typically at 60 Hz). It seems you currently have it in the Begin routine tab, which means the check is only done once per routine, and in fact at a time before the stimuli have been displayed, so it isn’t possible for them to have been clicked at that stage.
You should also be saving the mouse button presses at the same time. Doing this again at the end of trial might miss any press, as it has already been detected earlier (at least, that is how keyboard checking works).
thanks @richard for the tip with the tripple-backticks! i didn’t saw it in the reply box!
@Michael thanks! the problem was that it just cheked at the beginning! i put it in the every frame tab an it worked after some changes in the code:
i had to put the “foundtarget1 = 0” at the beginning of the experiment some rows up
and “thisExp.addData(‘Target_1’, foundtarget1)” above “thisExp.nextEntry()” because the code element puts these things a few rows too low
So thank you all for your Help! I’m so excited that this is working now!