Howdy, Stranger!

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

Supported by

Variables and the script in OpenSesame

  1. I try to use inline script element to randomise the images in my exp with the following code:

`
import glob
import random
img_list = glob.glob("/Exp/Imges_K/*.png")

random.shuffle(img_list)
`
The variable "img_list" exists, I can print it, I see it in the variable inspector, but if in the next sketchpad i try to use it as:

draw image center=1 file=[my_image_list[0]] name=pic_1 scale=1 show_if=always x=0 y=0 z_index=0
I get the error, that such variable does not exist.

I've checked tutorials and tried also add it to inline script var.my_image_list = img_list and again call it from sketchpad, but I have the same error
What did I wrong?

  1. Could I get somehow python script that OpenSesame create? I mean, when I press the button "general script" it starts from "set" functions. I can't see which libraries are imported, and which functions are actually used. Is it possible to get somehow? Where does this parameters from the "set" function pass to?

Thank you so much for help!

Comments

  • Hi Liya,

    As you already discovered, variables have to exist as part of var if you want to use them in sketchpads. So, while the variable img_list cannot be used in sketchpads, the variable var.img_list can. Another potential source of the error could be the phase in which you define the list. It should be done in the prepare phase of the inline script.

    2)

    Unfortunately, it is not possible to generate a script from your experiment. It might be a useful addition, but I don't think it currently has priority. Sorry.

    Eduard

  • Hi, Eduard!

    I've tried var, but seems I still do something wrong.

    Here is my code and the result of the quick run:


    I've also tried the version with square brackets, but the result is the same:

  • Could somebody explain me, please, what's wrong with var here? Why doesn't it work? Thanks!

Sign In or Register to comment.