Howdy, Stranger!

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

Supported by

[open] Randomizing Photo Location in OpenSesame

edited November 2013 in OpenSesame

We are creating an experiment in open sesame. We have images appearing randomly but only on the right side of the screen. How do we change it so it will choose an image from the file pool and put it on the left or right side of the screen in random order

Comments

  • edited 11:28PM

    Hi Nikki,

    Welcome to the forum!

    Perhaps you could do something like the following:

    Firstly, define the x_coordinates of the images in your block loop, for the right visual field only (i.e., all coordinates are positive).

    image

    Secondly, determine whether the current photograph should appear on the left or the right, by randomly choosing between 'left' and right' at the beginning of your trial. More specifically:

    • Append an inline_script item to the beginning of your trial sequence.
    • Put something like the following in its Prepare phase tab (see comments for more explanation):
    # Import the Python module 'random':
    import random
    
    # Use the function random.choice() to randomly choose 
    # between the values 'left' and 'right':
    visual_field = random.choice(["left", "right"])
    
    # If image will appear in the left visual field, we have
    # to make the in-the-loop defined x coordinate negative:
    if visual_field == "left":
    
        # Use the built-in OpenSesame function self.get() to 
        # retrieve the (always-positive) x coordinate
        # from the block loop:
    
        # See also:
        # http://osdoc.cogsci.nl/python/inline-script/#inline_script.get
        old_x = self.get("x_loc")
    
        # Make the x coordinate negative:
        new_x = -old_x
    
        # (Re)set the variable 'x_loc' by using the
        # built-in Opensesame function exp.set():
    
        # See also:
        # http://osdoc.cogsci.nl/python/inline-script/#inline_script.set
        exp.set("x_loc", new_x)
    
    # Finally, also set the variable 'visual_field', such that it
    # becomes available in the graphical interface (e.g. the 
    # logger item) as well:
    exp.set("visual_field", visual_field)
    

    Finally, use the square-bracket method to show the image at the desired location, by using a sketchpad item:

    image

    Does this answer your question?

    Best,

    Lotje

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

Sign In or Register to comment.