Howdy, Stranger!

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

Supported by

[solved] Inline code variables not working in sketchpad

edited June 2014 in OpenSesame

A small example of my problem.

*I have 61 jpegs in a folder

I've created a loop (w/sequence) with 61 items (named 1.1.jpg, 1.2.jpg...etc) under a variable named picture1. In this loop, I have the following inline script:

self.experiment.picturesBear=[]     #I create a picture list

self.experiment.picturesBear.append("picture1")  #I populate this list with picture 1 items

[The loop repeats 61 times, sequentially going through each item and adding it to the list]

I then have a sketchpad where I add all 61 items to the file pool. I change the sketchpad script to the look like this:

draw image 0 0 "[self.experiment.picturesBear]" scale=1 center=1 show_if="always"

I get the following error:

[self.experiment.picturesBear] could not be found in sketchpad.  Make sure that the file is present in the file pool (or specify the full location of the image in the script editor).

What should I do? Thanks in advance for the help

Comments

  • edited 10:28AM

    Hi,

    The variable you are referring to in the skecthpad is a Python variable that cannot be referred to within the OpenSesame syntax. What you could do, is add a variable to your loop called picnr. The value should be a numbers from 0 to 60.

    Next, add an inline_script to the sequence that contains your skecthpad, containing the following code in the Prepare phase:

    # select the picture name
    pic = self.experiment.picturesBear[int(self.get("picnr"))]
    
    # next, set the picture name as an OpenSesame variable
    self.experiment.set("picname", pic)
    

    In the sketchpad, use the following:

    draw image 0 0 "[picname]" scale=1 center=1 show_if="always"
    

    Good luck!

Sign In or Register to comment.