Help with a script
Hi Opensesame people!
I am building a working memory task for my PhD work. The description of the task is as follows:
_ A black “+” symbol is displayed at the center of the screen for 500 ms as a reminder to the participants to pay attention. Subsequently, a blank screen is displayed for approximately 600 ms before a letter series appears. The letter series contains 4–12 uppercase letters that appear sequentially, with each letter being displayed for 750 ms. After the letter series disappears, three of the letters reappear at the center of the screen for approximately 1500 ms. Participants must determine whether these **three letters were the last three letters of the previously displayed series**_.
I have attached the experiment file below.
I have the following variables:
Stimulus_set (4 to12) X Target (Present vs absent/"on" vs "off")
In order to present letters I have written the following inline code:
import random
import string
letters = list(string.ascii_uppercase)
stimlist = random.sample(letters, var.Stimulus_set)
canvas_letters = ['x']*13 ## creating an empty list
for i in range(0,len(stimlist)):
canvas_letters[i] = stimlist[i] ## filling the list with real letters
if var.Target == "On":
var.tar = canvas_letters[-3:] ## extracting last three items from the series of letters
if var.Target == "Off":
var.ntar = random.sample(letters, 3)
**The problem is that during the target condition the task sometimes displays Xs like ["x", "x", "x"]. **
Lastly, instead using the above code I could use for loop to loop through all the stimulus_set conditions and then make a list of letters to be displayed:
for in range(Stimulus_set):
stimlist = random.sample(letters, i)
But here I get a list out of range error.
Can anyone please guide me on this??
Thanks
Vatsal
PS: I had a similar task that had a list out of range error while using for loop which I had posted its solution gave me the code mentioned in the start of this post.
Comments
Hi Vatsal,
The problem is the line:
var.tar = canvas_letters[-3:]
The code is designed is such a way to avoid the list index out of range error by making a filler list that looks something like this:
['B', 'J', 'P', 'T', 'W', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x']
So, only the first items are the targets you would like to use, if you select the last three items and the stimulus set is not 12, you will end up with the three x's.
This could be solved by:
A = canvas_letters[:3]
Selecting the first three items, but I am not sure if that is what you would like to happen when target is 'On' . The for loop you suggest leads us back to the first problem of creating a stimulus list that is not compatible with the code inside the sketchpads since it creates a list that is too short.
Good luck,
Roelof
PS: for future reference try to keep the number of topics limited by posting in the same discussion, this keeps the forum tidier
Hey Roelof!
Thanks for replying.
Unfortunately I need to select the last three letters from the series not the first three.
Apologies for posting a fresh topic. I will keep that in mind next time.
Thanks
Vatsal
Hey!
Little heads up I solved the issue by adding a piece of code before the tar variable in the target on condition:
if var.Target = "on":
L = var.stimulus_set
tar2 = canvs_letter[0:l]
var.tar = tar2[-3:]
Hey Roelof!
PS: I was not sure whether I should post it as a new discussion. Pardon me if I am wrong.
In the same project I am developing a new task that is variant of stroop task. Here instead of colors and words I have to use numbers and their font size.
The task is simple: two numbers are presented on the screen briefly (100ms). Thier font size is different one being a larger in font size another being lower. The participant has to press a key to decide which number is larger in value while ignoring the its font size.
I have defined the variables as follows
ISI (800, 900, 1000, 1100, 1200) X size1 (20) X size2 (36) X flip (yes vs no)
The variable flip== "no" means the left digit is larger in size than the right one
while flip == "yes" means the right digit is larger in size than the right one
I am using the an inline script to generate numbers randomly. Also, I am using an inline script to create a variable called "correct_response" since the response key would be different in each case and i could not write it up in the loop item.
if digit1 > digit2 and var.response_response1 == "z":
var.correct == 1
else:
var.correct == 0
if digit2 > digit1 and var.response_response2 == ".":
var.correct == 1
else:
var.correct == 0
Also, the analysis of the participant's response is that a person's response time or accuracy will vary in conditions were there is miss match between the digits size (incongruent condition) and its value versus the condition where there's match between the digit size and its value (congruent condition). For this purpose I have also written an inline code.
if digit1 > digit2 and var.flip == "no":
var.incog == "yes"
else:
var.cong == "yes"
Coming to the issues I am facing:
1.There seems to be a fewer trials in the incongruent condition
2.The log file doesn't log the correct responses
I would be grateful if you could look into it. Experiment file attached.
Thanks
Vatsal
HI vatsal,
I changed your code a little. have a look here:
It looked fine, just a couple of redundancies. Also, be careful not to confuse
=
with==
. This caused the issues with the congruencies.Finally, you should be aware that they way you sample numbers currently, does not exclude the possibility that you have twice the same number, which will also cause the congrueny/incongruent varaible to be skewed.
Good luck,
Eduard
Hey Eduard!
Thanks for the reply and edition in the experiment. I am working on a more controlled way of sampling numbers which could creates a balanced number of congruent and incongruent conditions.
Thanks again
Vatsal
Hey Eduard!
In reference to my previous problem where I was not able to balance the number congruent and incongruent trials in my experiment. I added a new piece of code:
I have also made some changes in the sequence of loop. Where I have added two more sketchpads to incorporate the "incongruent" trails.
However, running the experiment gives me an error:
'int' object has no attribute 'getitem'
I have come across this error previously also when I used the random.randint function.
Would be grateful if you could look into it. Experiment attached
Thanks
Vatsal
Hey @eduard
Still I am unable to find the solution for this.
Hi Vatsal,
It has been some time, sorry. Can you please summarize what the goal is, what we accomplished so far and what outstanding issues we have?
Thanks,
eduard
Hey Edward !
Thanks.
It took me some time to reply but I could resolve the issue.
Solution was to create a fresh experiment with little changes and instead picking up the items from the list I simply made seperate experimental variable in an inline script using var. command. That did the trick
Thanks again
Vatsal