Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Assigning SOA randomly without repetition with Inline Script

S_HS_H
edited May 2016 in OpenSesame

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

  • edited 11:01AM

    Hi S_H,

    Using print in inline script might give you some insight in a situation like this.

    print self.experiment.get("ChooseSOA")
    

    will print '0'

    print ChooseSOA
    

    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:

    import random
    ChooseSOA=[100 for i in range(50)]+[200 for i in range(55)]
    random.shuffle(ChooseSOA)
    self.experiment.set("ChooseSOA",ChooseSOA)
    

    Another thing; instead of

    self.experiment.set("SOA", self.experiment.get(ChooseSOA.pop()))
    

    you want to use

    self.experiment.set("SOA", self.experiment.get('ChooseSOA').pop())
    

    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

  • S_HS_H
    edited 11:01AM

    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 print in order to spot the problem. at the end of the first script I wrote print(len(ChooseSOA)) and the length was 105, as it should be. at the beginning of the second script(before setting "SOA") I wrote print(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!

  • edited 11:01AM

    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:

    self.experiment.set("SOA", ChooseSOA.pop())
    print self.experiment.get("SOA") #to check
    

    Note you will have to do

    self.experiment.set("ChooseSOA",ChooseSOA)
    

    after the shuffle if you want to be able to log the complete ChooseSOA list with the logger item!

Sign In or Register to comment.