Howdy, Stranger!

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

Supported by

[solved] variables in sketchpad

edited January 2014 in OpenSesame

hi again!

i am wondering how to use variables in a sketchpad. i tried to set a global var in an inline_script (run_phase) and point to it in a sketchpad...no success.

i would like to do following:

create an array and shuffle it like

pic = [
["001.jpg","aaa","bbb","ccc"],
["002.jpg","ddd","eee","fff"]
]

random.shuffle(pic)

and show a random pic in the sketchpad like

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

any hints?

thanks,

ben

Comments

  • edited 11:16PM

    Hi Ben,

    Inline_script items require Python coding, whereas sketchpad items require OpenSesame coding. You cannot mix the two.

    In your case, I think it's best to determine which picture to show in your inline_script item, and to subsequently set this variable for future use in the GUI (i.e., the sketchpad item). Next, you could simply use the square-bracket method in the skechpad item.

    So:

    In your inline_script:

    import random
    
    picList = [
    ["001.jpg","aaa","bbb","ccc"],
    ["002.jpg","ddd","eee","fff"]
    ]
    
    random.shuffle(picList)
    
    # Declare variable:
    pic= picList[1][0]
    
    # Set variable for future use in the GUI.
    # For more info, see:
    # http://osdoc.cogsci.nl/usage/variables-and-conditional-statements/#getting-and-setting-variables-in-inline_script-items
    exp.set("pic", pic)
    

    In the sketchpad editor, use the square-bracket method:

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

    For more information, see:

    Does this help?

    Best,

    Lotje

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

  • edited 11:16PM

    cool! works fine! thanks a lot! cheers, ben

Sign In or Register to comment.