Storing and displaying trial responses in real time
Hello everyone,
I am new to OpenSesame and I am currently trying to design an online experiment on risky choices. During the process I ran into the following 2 issues:
1. The image below represents how the display of our experiment should look like. The squares on the screen represent the different trials. There are 40 squares in total, and therefore 40 trials. The yellow square essentially acts as a tracker that indicates in which trial the participant currently is. In addition, in each trial the participant can either choose option (a) or option (b). The trials where the participant has chosen option (a) should be “stored” with a blue color and the trials where the participant has chosen option (b) should be marked with the color red. In other words, we want the experiment to exhibit “memory” by storing the participants’ responses in terms of color. The experiment should keep track of the choices of a participant so that if, for instance, a participant is in trial 13 they can see how they responded in trials 1 to 12 by means of the assigned colors.
I have managed to partially create this display on OpenSesame (condition B of the file attached to this post). When I choose option (a) the color of the corresponding trial turns blue and when I choose option (b) the square turns red. Nevertheless, the history of responses and their corresponding colors are not “stored” as they do not remain on the screen. Currently the only response visible to the participant is that of the last trial, as depicted in the image below:
2. In another condition, we would like the experiment to again exhibit “memory” but this time in a different way. If possible, we would like to recreate the display shown below, where the participants can see a square across trials that displays their responses in terms of the proportion of options (a) and options (b). For example, up to the trial shown below, the participant can see that they have selected a higher number of choice (a) responses (shown in blue) compared to the lower number of (b) choices (shown in red).
Any assistance or tips on how to proceed would be greatly appreciated!
Thank you in advance,
Constantinos
Comments
Hi Constantinos,
This sounds like a fun experiment. I adapt your experiment somewhat to make the first part work. Note, I only implemented the first 10 boxes (it is a lot of copy and pasting in the sketchpad skript).
The second part is a bit more complicated. I haven't yet tried to do it, I might do it later though.
But most importantly, you have to keep in mind that if this study is supposed online, you cannot use python inline script. For the sakes of demonstration, I still used python, but in a way that would make translation to Javascript rather easy.
I hope this helps a bit. Let me know if you need more help.
Good luck,
Eduard
Hello Eduard,
Your response has been very helpful! The first 10 trials of your file look exactly how we want condition B to look like. The only problem is that this solution does not work for one of our sequences where the choice values are randomized (by setting the order of the loop from “sequential” to “random”). The consequence of this is that the "trial_no" variable does not track the order of the trials anymore, something which messes things up. Do you maybe know how to tackle this?
I would also appreciate any guidance on how to implement the second part, however you have already been of great help. Thanks a lot for that.
Kind regards,
Constantinos
Hi Constantinos,
In this case don't define this variable in the loop table but increment it in each inline_script
So in the beginning of every block (before the trial sequence), you have to initialize the response (e.g.
var.trial_no = 0)
, and later in the inline_script (before you set the color), increment the variable (var.trial_no += 1
). The same you can do in the conditions that currently work.Hope this helps,
Eduard
Hello Eduard,
After following your instructions I was able to progress and create a complete sequence that works perfectly fine. I appreciate the time you have put into this.
However, when I try to copy the whole setup in order to create two more sequences, a problem arises in the transition between these sequences. What seems to be the problem is that the responses of the first sequence get carried onto the second sequence, whereas the feedback item should reset in every sequence.
I tried to tweak the code to make it work but my limited programming skills don't seem to help. I also tried copying the first inline script and pasting it the beginning of the second sequence, so that in the new sequence the variables are overwritten/reset. The result was that although the responses of the first sequence were erased from the feedback item of the second sequence, new responses stopped being recorded as blue and red squares. The third sequence seems to work somewhat fine (with the only issue being that it starts on the 2nd trial and it ends on the 42nd trial instead of starting on the 1st and finishing on the 40th).
Kind regards,
Constantinos
Hi Constantinos,
Which of the two files should I check?
Eduard
Hello Eduard,
The first file is the one where only the first sequence works. I think it would be easier to check that one as it is closer to the version that you posted a few days ago.
Kind regards,
Constantinos
Hi,
Yes, you have to reset variables in between the blocks. I copied the initial inline_script, but you can also adjust the contents if you want to reset selectively.
I also added 2 comments to the inline_script within the loop.
Does this help?
Eduard
oops. forgot to attach a file....
Dear Eduard,
I have tried to reset the variables in between the blocks but that does not seem to solve the problem, as I do not get a new "clean" feedback item in each new sequence. Instead, the responses of the previous sequence are kept on the display. I specifically added the "var.trial_no = 0" command into the inline_script before each new sequence but this does not stop OS from leaving on screen the responses from the previous sequence. Below I include two screenshots that might help illustrate better what I am describing.
The responses recorded in the first sequence.
Currently being in the second sequence, and instead of OS recording my responses in this sequence it displays the responses recorded in the first sequence. I therefore do not get feedback on my responses in the trials of the current sequence.
Kind regards,
Constantinos
Oh yeah, sure. Setting trial_no is not enough. You have to redo all the colors again. So what happened in the very first inline_script if I remember correctly.
As it turns out, the experiment was not working properly because in some of the incline_scripts I was inserting the commands in the "prepare" phase instead of the "run" phase. Below I attach the file with the progress that has been made so far (in case someone finds this useful). Thanks again to Eduard for his valuable contribution in completing this stage of the experiment.
Hello,
I am currently working on the final part of this experiment (condition C) where we want to present to the participants their responses on conditions A and B for the corresponding sequences of each single trial. If, for instance, currently a participant is in trial 12 of sequence "ID" of condition C, they shoud be seeing on the display their previous choice from trial 12 of sequence "ID" of condition A and their choice on trial 12 from sequence "ID" of condition B. If in those conditions they opted for choice "a" and "a" respectively, then both halves of the square corresponding to trial 12 should be blue. If alternatively they responded "a" and "b", then the color of the current trial square should turn half blue and half red (as depicted below).
*Please note that the colored square does not have to be bigger than the rest of the (trial) squares as shown above.
I was thinking that a potential solution would be to introduce an inline_script in which there is a for loop that overwrites in each trial the variable "response" and saves each trial response as a new variable (e.g., response_trial1, response_trial2, etc.) In this way I can later use the "show if" function to make each blue and red half-square appear depending on the participants' responses in the previous trials. It should be created in a way that the var.response_trialx is equal to var.response so that "x" represents the trial number. Up to now I have not been able to create a loop that creates new variables based on the current trial number. Could someone give me any advice on how to create such a for loop?
Thanks in advance!
Constantinos
Hi Constantinos,
Do you still have the problem?
I was thinking that a potential solution would be to introduce an inline_script in which there is a for loop that overwrites in each trial the variable "response" and saves each trial response as a new variable
That would work, but I guess it is easier if you have a list for every condition to which you simply append the current respond. That list you can then access later and color the squares based on it.
For the coloring part, I think it is as easy as doubling the number of colored squares in the sketchpad, and cutting their width in half. Then check the entry of the list of the right condition and the right index (based on trial number), and assign the colors accordingly. The latter procedure shouldnt be much different from the rest of the experiments that I helped you with.
Hope this helps,
Eduard
Hello Eduard,
Unfortunately I am still stuck in that part. Could you please further explain how I could implement the first part of your solution? How would I create the list to which I can append the current response?
Thank you
Hi,
I added some pointers on what I mean.
For testing purposes I disabled sequence B, not that you wonder.
Hope this helps,
Eduard
Dear Eduard,
I tried to follow your advice and I have made some progress, however there are still some issues:
1) The colors of the half-squares seem to not always correspond to the right trial responses. For example, in the ID sequence of condition C I can (correctly) see the responses from the corresponding trials of the ID sequence from conditions A and B, however the experiment does not correctly match the responses from the trials of the DI sequence to the right colors.
2) Is there a way to present only responses relevant to the current trial (in a way that the participants can only see the colored half-squares of the current trial and not of the previous trials)?
So that it looks like in the image below and not like in the screenshot above:
Thanks again,
Constantinos
hi Constantinos,
Sorry for the long delay, this semester is very busy for me...
2) Is there a way to present only responses relevant to the current trial (in a way that the participants can only see the colored half-squares of the current trial and not of the previous trials)?
Yes, basically, at the end of every trial you have to change the colors back to white of the relevant blocks. Should be straightforward. What you do to set the colors, should be redone on the previous blocks. Does that make sense?
Regarding question 1, I am not sure I correctly understand. Do you mind to explain in more detail please? If you have the problem still, that is.
Hope this helps,
Eduard
Hello Eduard,
Thank you for getting back to me and sorry for the late reply. Things have been busy with the study.
At some point after trying some things out with the code I understood how it works and I was thankfully able to solve both issues mentioned in my previous post. I would like to thank you again for all the support because without your help the experiment would not have been completed by now.
Below I am attaching the final version of the experiment in case someone finds it useful.
Kind regards,
Constantinos
Hi Costantinos,
Thanks for sharing and good that it works now! Happy data colletion!
Eduard