Howdy, Stranger!

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

Supported by

Variable from the loop is not recognised on a following inline script

Hello everyone!

In my current experiment, I am trying to show certain images in a sketchpad and then in a following canvas created from an inline script (it will also contain a slider). My aim is to use the same image in the sketchpad and the following canvas, for every circle.

For this reason, I defined a variable in the loop as the one you can see in the following image:

The images were presented correctly. Then, I wanted the same picture to be presented in the following canvas, so I wrote this, using the var.target:

from openexp.canvas import canvas
from openexp.mouse import mouse


my_mouse = mouse(self.experiment, timeout=20)
my_canvas = canvas(exp)
my_canvas.clear()
my_canvas.text("")
my_canvas.image(var.target,True, 0, -160, scale=0.6) 
my_canvas.prepare()
my_canvas.show()
self.sleep(0)

However, this leads to the following error:

Any suggestion on what I have to write in order to draw a certain [target] value from the loop to the canvas?

Thanks in advance,

Eliza

Comments

  • edited November 9

    Dear Eliza,


    Thank you for your detailed description.

    I think your script will work if you add a line in order to retrieve the absolute path to your jpg files and then refer to this path (instead of the name of the jpg):

    from openexp.canvas import canvas
    from openexp.mouse import mouse
    
    
    my_mouse = mouse(self.experiment, timeout=20)
    my_canvas = canvas(exp)
    my_canvas.clear()
    my_canvas.text("")
    
    
    # Retrieve the absolute path:
    path = exp.pool[var.target]
    
    
    my_canvas.image(path,True, 0, -160, scale=0.6) 
    my_canvas.prepare()
    my_canvas.show()
    self.sleep(2000)
    
    


    Best wishes,


    Lotje

  • Lotje thank you for the immediate and helpful response.

    I added the line you proposed, and everything plays perfectly!


    Thanks again,

    Elisa

Sign In or Register to comment.