Howdy, Stranger!

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

Supported by

How to link the inline python script with sketchpad or some changes in the code

Hi

I am designing an experiment where I have to fix the target position in one coordinate and randomize distractor location in other three coordinates and with random faces. I have coded it for distractor location and stimuli but I am stuck in the part as in where do I have to modify in the element script. Kindly help

Comments

  • Hi vani,

    there is very little information to help you.

    I imagine that you created variables in a loop for the target positions and distractor locations. You can randomize it directly in the loop.

    Later in the sketchpad item you can use these variables for the locations.

    Is that what you need?

    Cheers, Stephan

  • Hi Stephan,

    Sorry, I figured out I have given minimal information about my experiment. So, basically i have made condition file for target faces and position. My target is a neutral face and I am using 4 male and 4 female face. Same goes for my distractor which is a fearful face(4 male , 4 female). Both distractor and the target has to appear simultaneously but for the entire block of trials target position will be cued(mentioned it in the condition file). I have to randomize distractor position and faces for the block of trials . I am having trouble in modifying the element script for distractor stimuli. I have also included an inline script before stimulus sketchpad but it's still not running. I am sharing my code here. I am new to open sesame :') . Thanks again


    Regards,

    Vani

  • Hi Vani,

    Maybe I am missing a critical point, but what you describe sounds very similar to our beginner's tutorial. Have you worked through it? I think you can use its logic to implement your task. You can also check Sebastiaan's youtube channel. He shows there how to implement a couple of experiment, some of which sound like what you are trying to do. Can you check that and let us know whether you still need help?

    Good luck,

    Eduard

    Buy Me A Coffee

  • Thanks Eduard, yeah it's kind of similar to gaze cueing but it is precisely to say, a four location variant Posner task and instead of one kind of distractor I have multiple emotional faces and I am using male and female faces. If I put the distractor information in the condition file, It would be too long and cumbersome. So, I was wondering if could code for the distractor part in the inline script and call in the sketchpad.

  • Hi @vani


    If you're good at coding, you could have a look at the Canvas class and its functions:



    And yes, you could also define variables in inline_script items using the var object:



    And you can run previously-prepared items by setting the Run-if statement of the corresponding item to "never" and using the following code in the Run tab of your inline_script item:


    items.execute("my_sketchpad")


    See:



    Hope this helps!

    If you want more precise answers, could you please attach your experimental script?


    Cheers,


    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • hi @lvanderlinden

    I have attached my experiment and messaged you. Also, do I need to modify the random stimulus element script too according to the inline script. I think I am getting lost in that part. Thankyou again.

  • Hi @vani

    I didn't receive your message. Could you attach your experiment here by clicking the paperclip icon below?


    Cheers,


    Lotje

    Did you like my answer? Feel free to Buy Me A Coffee :)

  • Hi @lvanderlinden

    PFA


    I am still unable to figure out how to make my distractor inline script work with the stimulus sketchpad. Basically, in the window I have to cue the target for the block of trials and randomize 8 distractor faces in three positions apart from target's position. Target and distractor appear simultaneously. I am attaching my experiment. I really appreciate this. Thankyou again.

  • Hi @vani


    In order to randomly select a distractor face and distractor position, you could replace your Python inline code with the following piece of script:


    import random
    
    # List of all coordinates:
    list_coords =["-160,-128", "160,-128", "160,128", "-160,128"]
    
    # Remove the current target location:
    list_coords.remove(var.target_pos)
    
    # List of all distractor faces:
    list_bmps = ["1F2.bmp", "2F3.bmp", "3F3.bmp", "4F3.bmp",
                    "5F3.bmp", "6F2.bmp", "7F3.bmp", "8F2.bmp"]
    
    # Randomly choose a distractor position:
    var.dist_pos = random.choice(list_coords)
    var.x_dist = var.dist_pos.split(",")[0]
    var.y_dist = var.dist_pos.split(",")[1]
    
    # Randomly choose a distractor face:
    var.dist_bmp = random.choice(list_bmps)
    


    Next, replace the OpenSesame script in the sketchpad code and use the square-bracket notation:


    set duration 0
    set description "Displays stimuli"
    draw image center=1 file="[target_face].bmp" name=target_face scale=1 show_if=always x=-160 y=128 z_index=0
    draw image center=1 file="[dist_bmp]" name=distractor scale=1 show_if=always x="[x_dist]" y="[y_dist]" z_index=-1
    


    I also uploaded an example.


    (Note, however, that by randomly selecting bmp and coordinates, certain combinations could appear multiple times in a block, whereas other combinations might, by chance, not occur at all.)


    Hope this helps!


    Cheers,


    Lotje


    Did you like my answer? Feel free to Buy Me A Coffee :)

Sign In or Register to comment.