Assigning SOA randomly without repetition with Inline Script
Hi Everyone!
I'm trying to run a loop of 105 Prime-Target stimuli while each Prime-Target pair will be called randomly and will be assigned with a random SOA from 105 SOAs list. I'm having a problem with the SOAs assigning.
Before the Prime-Target loop, I set in Inline_Script the variables as follow:
import random
self.experiment.set("ChooseSOA",0)
ChooseSOA=[100 for i in range(50)]+[200 for i in range(55)]
random.shuffle(ChooseSOA)
Then, in the sequence running in the loop I wrote:
self.experiment.set("SOA", self.experiment.get(ChooseSOA.pop()))
Then, I added a sketchpad with the duration "SOA".
when I'm running the experiment, the OpenSesame says:'int' object has no attribute 'pop'
Help? Anyone?
Comments
Hi S_H,
Using print in inline script might give you some insight in a situation like this.
will print '0'
will print your list [100, 100, 100, 200, etc. ]
Basically you use both a local and a global variable ChooseSOA. You could make this work by filling the global variable ChooseSOA with you local list instead of '0' like this:
Another thing; instead of
you want to use
because you are trying to pop a value from list self.experiment.get('ChooseSOA')
And last but not least if you are using OpenSesame 3 you want to be using the var object
Hope this helps and please correct me if I'm wrong,
Jarik
Dear Jarik!
Thank you very much for your kind answer!
I rewrote my code according to your detailed suggestions and now I'm having: "'unicode' object has no attribute 'pop'".
I used
printin order to spot the problem. at the end of the first script I wroteprint(len(ChooseSOA))and the length was 105, as it should be. at the beginning of the second script(before setting "SOA") I wroteprint(len(self.experiment.get("ChooseSOA")))and it oddly printed 616.Do you have any idea what am I doing wrong now?
(btw, I am using version 2.8.7 and I'm not able to update it at the moment...)
Thanks!
Couldn't find 2.8.7 so I used 2.9.7 to test:
I think you will be OK using the local variable ChooseSOA because all inline_script items share the same workspace:
Note you will have to do
after the shuffle if you want to be able to log the complete ChooseSOA list with the logger item!