Replacing one variable list with the values of another variable list using inline script
Hello,
I have prepared an experiment in Open Sesame in which participant's self-relevant information (e.g., name, surname, city, month of birth) is paired with a particular image stimuli (e.g., happy face) and as control I have used other-information (other names, surnames, cities and months) that are paired with different image stimuli (e.g., happy, neutral and sad faces). The words (self-relevant/other-information) are presented at random in different quadrants on the screen and after the participant clicks on those words, a face image appears on the same quadrant (happy face for self-relevant information/ sad, neutral or happy face for other-information). All of these trials belongs to the same block, and I have in total 240 trials.
I have the following inquiry though. Since sometimes participant's personal information might coincide with the control words (e.g., if input variable is Dave and I have Dave as a control word), I would like to use another variable list with different control words (e.g., Oscar) as cavnas text. So, for that purpose, I have created another variable (called alterantive_word_stimuli ) with the input variables (the responses given by the participants) and other control words. I have also created two other variables, one (called Responses) only with the input variables (responses given by participants) and another variable (called words_var ) only with the control words (the ones used originally). With this variables in mind I added an inline script in the beginning of the sequence (before fixation dot, word presentation, touch response and image presentation). I am not an expert in Python, but I have tried many if functions and none of them worked (Open Sesame did not send any error message, it just keep showing the original text variable (called word_stimuli). I have tried codes such as: if var.words_var == var.Responses: var.word_stimuli = var.alternative_word_stimuli.
I am attaching images of the inline script, and of the structure of the block with their respective variables.
I would highly appreciate if someone in this forum could provide me with some insight on how to proceed with this problem.
Thanks in advance.
Best, Anton
https://forum.cogsci.nl/uploads/320/0QIM51HCVJ41.jpg
https://forum.cogsci.nl/uploads/031/JIF6NCC7LZ04.jpg
https://forum.cogsci.nl/uploads/785/KG8JIS2Q0OOU.jpg - clear
Comments
Hi Anton,
If I understand correctly, you want to check the
loop
table for whether any of the values underResponses
matches any of the values underwords_var
. And if so, you want to use values fromalternative_word_stimuli
instead ofword_stimuli
(by assigning the former to the latter). Is that correct?If so, then it's important to first realize that you shouldn't check individual values, which is what you're doing now. This …
… checks whether on that particular trial,
Responses
andwords_var
are the same value. But it doesn't consider the columns as a whole. And this …… checks whether any of the characters in
Responses
areTrue
, which will be the case for anything other than an empty string, and then does the same forwords_var
, and finally compares if both either are or are not empty strings . Also very different from what you want to do!Below I added a function (
any_match()
) that checks what I believe you want to check, namely whether any values under two columns match, also taking into account variable references:I'll leave it as an exercise to figure out how to actually use
any_match()
in your code!Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan,
Thank you very much for your help! It's highly appreciated.
Indeed what I want to do is what you have addressed in the beggining of your response (check the
loop
table for whether any of the values underResponses
matches any of the values underwords_var
. And if so, you want to use values fromalternative_word_stimuli
instead ofword_stimuli
(by assigning the former to the latter)).I have tried run and exercise with the code you have provided me. But I am still getting the same word stimuli (word_stimuli) instead of the stimuli I want to use (alternative_word_stimuli).
My knowledge regarding python is quite limited. Thus I am assuming that I am doing something wrong with the code you have provided me.
I am attaching the code to see if you can help me again with this.
Thanks in advance.
Cheers!
Anton
Hi Anton,
I wasn't very clear about that, but the arguments to
any_match()
should be strings, like so:if any_match('Response', 'words_var_Block_1_Exp_St'):
Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan!
Thank you very much for your help!!
The any_match() function is working so far! I've tested this by adding an if function and ask to print me TRUE or FALSE if the condition is satisfied ( I can see it on the debug window) .
However, I am still having troubles regarding the second part of my question (replacing one variable - word_stimuli - with another variable -alternative_word_stimuli -) .
I have tried with many code lines, such as:
if any_match('words_var','Responses','Block_1_Exp_ST'):
my_canvas.text(text= "alternative_word_stimuli")
else:
my_canvas.text(text= "word_stimuli")
Or:
if any_match('words_var','Responses','Block_1_Exp_ST'):
var.word_stimuli[0:47] = var.alternative_word_stimuli[0:47]
else:
var.word_stimuli[0:47] = var.word_stimuli[0:47]
Or:
if any_match('words_var','Responses','Block_1_Exp_ST'):
var.word_stimuli[0:47] = var.alternative_word_stimuli[0:47]
else:
var.word_stimuli = var.word_stimuli
But none of these codes seem to work ( I enter information that satisfies the any_match function, and the program still shows me the items from word_stimuli). As I have stated earlier, I am not a python expert nor a programmer expert. So there must be something I am doing wrong.
I would highly appreciate if you can help me again with this.
Thanks in advance!
Best,
Anton
Hi Anton,
The reason that nothing has an effect is probably that you're doing it in the Run phase of the script, whereas most items (including
sketchpad
s) are prepared during the Prepare phase.So the first thing to do is move the code to the Prepare phase. Then, this should (I think) do the trick:
That being said, looking at all the things that you've tried, it seems that you're randomly trying things without understanding what they mean! That's frustrating, and also unlikely to result in success. So I would say: Why not familiarize yourself with at least the basics of Python? This will take a bit of time, but you will easily win this back in the medium-to-long term.
Cheers!
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan!
Thank you so much for your help! Everything is working great now!!
I will follow your advice and keep learning about python.
Cheers!
Anton