Creating clickable text alternatives

Hi guys,

What I’m trying to achieve is a task where an image is in the center and four alternatives appear in each corner of the screen. The objective is to choose the right one by just clicking one time with the left botton of the mouse and moving to the next image.

I already crated the task using Excel to assign four alternatives to each picture including the CorrAns column. The experiment is working pretty well, nevertheless, when the task is over, the data includes the x and y axis that the subject clicked but not if the answer was correct or incorrect (0 or 1)

The routine looks like this

Here is the excel condition file
condition_rmet.xlsx (9.8 KB)

Also, when I finish the experiment, the data of this specific task doesn’t save in the data folder, it actually saves in the experiment folder creating data files with the name of one of the images that I used in the task. Why is this happening? Any Ideas?

2 Likes

Hi @Bruno_Dalpiaz,

  1. The mouse object has a ‘isPressedIn’ method see here. This enables you to define a shape and see whether or not the mouse was registered in that particular stimuli i.e., your correct stimuli. However, textbox does not share this functionality as far as I can tell, so one workaround would be to define shapes that sit behind your text (see example experiment attached). In this example I have exaggerated the color and size of the shape surrounding the text, but you can change them to fit the text and blend with the background if you require. The correct answer information is stored in the conditions spreadsheet, and if the mouse is registered in the shape that shares the same location as the correct answer, then a correct answer (i.e., 1) will be written in your data file, otherwise not (i.e., 0).

  2. The data are not being written in a ‘data’ folder because you have defined a variable called ‘filename’ in your conditions file which clashes with the filename variable used by the experiment handler. Change the name to ‘filenameJPG’ or something other than filename, and you will no longer have this problem (see attached sheet)

condition_rmet.xlsx (8.5 KB)
exp.psyexp (18.8 KB)
.

2 Likes

Hi @dvbridges,

I really apreciate your response, I tried the things you proposed but I’m having trouble with the mouse properties.

Let me explain: the experiment is running quite well, but when I finish it the responses (1 or 0) aren’t saved, but all the other variables such as RT and mouse position are ok.

Comparing the mouse properties with the ones that you attached here, I see some specific ones that I don’t know how to apply in my experiment because when I try to add or modify a mouse component, they simply don’t show (clickable $, saveParamsClickable $, newClicksOnly). I don’t know if the code have anything to do with it, but i tried other alternatives using the ‘isPressedIn’ method and the properties just keep the same, so basically I can’t define clickable objects.

The data solution worked beautifully. Thanks for that.

Hi @Bruno_Dalpiaz, In the example given, I added a code component that determines whether or not a response is correct, and saves a value in a variable called corr (see ‘Each Frame’ of the code component). Then, at the end of each trial, more code in the in the tab “End Routine” adds the variable corr to the trialhandler using thisExp.addData('responseAcc', corr). This demonstrates a way to save any data you can obtain from the experiment, so you can have custom outputs rather than defaults. In your comment, you say you have variables such as “clickable”. In this case, you go to the code component in the tab “End Routine” and add thisExp.addData('clickable', clickable). Does that help?

Hi,
I will try to explain myself better this time.

I used the codes you said in the ‘each frame’ and the ‘end routine’ tabs, but i still didn’t get a ‘corr’ column in the data file. Here is how my datafile ands after the experiment:


What I meant in the previous post, is that when i compare the mouse properties that I have with the ones you sent, there’re some differences that i don’t know if they have any relation with the code. Let me show you:

the first one have my default mouse properties and the second is the one you send in your previous post.

Thank you very much, @dvbridges

@jon Sorry for tagging you here, but are those mouse Properties different because we use different Psychopy versions? Is there any code I can use to make the shapes clickable?

@Bruno_Dalpiaz apologies I have been using the most recent version of PsychoPy. However, you can change the mouse component to one that is compatible with Psychopy2 e.g., attached, and the isPressedIn function will still work. I am not sure why you are not getting your mouse data to output in your data file. In the example attached, you would see a column heading of ‘responseAcc’ rather than corr, because corr is the name of the variable holding the bool value of whether or not the mouse was pressed in the correct shape, not the name of the column heading.

exp.psyexp (18.5 KB)

@dvbridges No problem. I tried to use the mouse components you attached but i still couldn’t get the ‘ResponseAcc’ column in the data file :disappointed: I’m just getting the specific button I pressed and the axis numerical value.

Ok @Bruno_Dalpiaz, could I see your code component code please?

Here is the each frame component

if mouse.isPressedIn(eval(corrPos)):
    corr = 1
else:
    corr = 0

And this is the end routine component

thisExp.addData('responseAcc', corr)

these are the ones you were asking for, right?

Ok @Bruno_Dalpiaz that looks fine, but looking at your output I am wondering why you have duplicate information in your RMET_loop output?

I don’t think it’s duplicated data, @dvbridges

I’m getting pretty specific data from each button of the mouse component. Maybe specifying just the left button in the code? Is that possible? You think it may work?

Thanks @Bruno_Dalpiaz, I was not sure why you had so many columns, but that is fine. I’m not sure what is happening, but it may be worth adding some print statements to debug. For example, add a print statement after the conditional in the code component, just to make sure that the conditional if mouse.isPressedIn is working correctly. So, perhaps do:

if mouse.isPressedIn(eval(corrPos)):
    corr = 1
    print("{} for mouse function, and {} for corr variable".format(mouse.isPressedIn(eval(corrPos)), corr))
else:
    corr = 0

Then for the code in End Routine

print(corr)

This will at least show in the output whether the corr variable is defined properly.

Hi,

It seems that you have a similar issue to what I was doing recently. Perhaps this will help:

in short, it might be enough to use the following:

# check if the mouse is pressed within the current one:
if mouseresp.isPressedIn(your target image name):
    thisExp.addData('correct', '1')
else:
    trhisExp.addData('correct', '0')

However, I’m not sure this will work the same, since your 4 images appear to be text objects? Are you presenting your participants with images or words?

1 Like

This is what I got in the output after I add the print statements, @dvbridges :

Running: C:\Users\Bruno Dalpiaz\Desktop\experimento\julgamento moral\experimentoJM_lastrun.py
pyo version 0.8.7 (uses single precision)
0
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
0
0
0
True for mouse function, and 1 for corr variable
1
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
False for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
1
0
True for mouse function, and 1 for corr variable
1
True for mouse function, and 1 for corr variable
1
0
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
1
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
1
0
0
0
0
0
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
0
0
0
0
0
0
0
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
0
True for mouse function, and 1 for corr variable
1
True for mouse function, and 1 for corr variable
1
True for mouse function, and 1 for corr variable
1
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
0
True for mouse function, and 1 for corr variable
1
0
0
True for mouse function, and 1 for corr variable
1
True for mouse function, and 1 for corr variable
1
0
True for mouse function, and 1 for corr variable
1
True for mouse function, and 1 for corr variable
1
11.4746 ERROR avbin.dll failed to load. Try importing psychopy.visual
as the first library (before anything that uses scipy)
and make sure that avbin is installed.

Running: C:\Users\Bruno Dalpiaz\Desktop\experimento\julgamento moral\experimentoJM_lastrun.py
pyo version 0.8.7 (uses single precision)
0
True for mouse function, and 1 for corr variable
1
0
True for mouse function, and 1 for corr variable
1
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
1
True for mouse function, and 1 for corr variable
1
True for mouse function, and 1 for corr variable
1
True for mouse function, and 1 for corr variable
1
True for mouse function, and 1 for corr variable
1
0
0
0
0
0
0
0
True for mouse function, and 1 for corr variable
1
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
1
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
1
0
0
True for mouse function, and 1 for corr variable
1
0
True for mouse function, and 1 for corr variable
1
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
1
True for mouse function, and 1 for corr variable
1
True for mouse function, and 1 for corr variable
1
0
0
0
True for mouse function, and 1 for corr variable
0
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
False for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
1
0
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
1
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
True for mouse function, and 1 for corr variable
1
0
0
3.9482 ERROR avbin.dll failed to load. Try importing psychopy.visual
as the first library (before anything that uses scipy)
and make sure that avbin is installed.

Thanks, you should not be getting False for mouse function, and 1 for corr variable because False would mean that the mouse was not pressed in the shape and so corr should be zero. As @agata suggested, perhaps this can be simplified if you do not need a response variable to work with. So, remove all code from the Each Frame tab, and clear the End Routine tab and enter the following:

if mouse.isPressedIn(eval(corrPos)):
    thisExp.addData('responseAcc', '1')
else:
    thisExp.addData('responseAcc', '0')

@dvbridges I’m getting the same output data file I did before, even if I change the column variable name.


@agata The responses are not images contained in my condition file, they’re translucid objects over the four text alternatives. Therefore, the condition file contains wich object is correct for each image that is presented in the center of the screen.

Ok @Bruno_Dalpiaz, would you be able to upload your experiment files here (not the jpgs, I will just delete the jpg presentation)? This would be very helpful as I cannot tell from this information why this problem persists, as it works ok in my example.

I belive this is all I got for the experiment, @dvbridges

condition_rmet.xlsx (10.0 KB)
Dilemas_Morais_A.xlsx (15.3 KB)
Dilemas_Morais_B.xlsx (14.0 KB)
experimentoJM.psyexp (73.7 KB)