Howdy, Stranger!

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

Supported by

[open] changing property of an item in a sketchpad at runtime

edited May 2015 in OpenSesame

I am trying to find a way to change/update some sketchpad's items with an inline script which runs right after the sketchpad (duration 0), but I guess there is no easy way to access a sketchapd' sub-items property, so fo now I'm using (a lot of) variables inside the sketchpad'script like this:

draw textline -192 -224 "[text1]" center=1 color="white" font_family="mono" font_size=[fontSize] font_bold="[doBold]" font_italic="no" html="yes" z_index=0 show_if="always"

the most useful would be looping trough all the items and accessing each item as if it was a single object, with its properties, and change them. A sort of of:

for myItem in exp.items['mySketchpad'] : 
    if myItem.name == "my_textline":
        myItem.text="newtext"

thanks

Comments

  • edited 8:16AM

    Hi,

    It's not easy to change the contents of a sketchpad by accessing the item in the way you're doing now. However, what you could do is create a canvas object that is a copy of a sketchpad, and work on that. For example, you could create a copy of mySketchpad and add a fixation dot like so:

    c = self.copy_sketchpad('mySketchpad')
    c.fixdot()
    c.show()
    

    See also:

    Does that help at all?

    Cheers,
    Sebastiaan

  • edited 8:16AM

    Ehm.. yes and no. In the meaning that I am already trying that way.

    I thought that from InlineScript it would be possible to access the internals and working directly with the objects themselves without doing a lot of variable declarations and going strighlty to the solution in a no complicated way.

    But ok, I guess it's just a matter of "know-how-things-works"

    thanks for your help

  • edited 8:16AM

    E.g., which is my problem now.

    I have a sketchpad (duration 0) with a lots of items (texts and rects) defined in a way that they should appear upon a user response.

    So each item has a show_if="['var1'] =='yes'" condition.

    The way I found to reload the sketchpad and its item, showing or not is putting inside a sequence:

    mySequence
    --- Sketchpad
    --- inLineScript
    

    inside the inLineScript there are these lines:

    exp.set('var1','yes')
    exp.items['mySequence'].prepare()
    exp.items['mySequence'].run()
    

    and yes, it works but takes some time to reload.

    I like the c = self.copy_sketchpad('mySketchpad') approach instead which is fast but I don't know how to switchOn those items that are initially "hidden" .

    thanks!

  • edited 8:16AM

    I think that is actually a good solution, and quite easy to implement.

    and yes, it works but takes some time to reload.

    That's because the whole canvas is regenerated. This takes some time, especially on the hardware-accelerated backends (xpyriment and psycho). Does it go faster if you switch to the legacy backend?

    Cheers,
    Sebastiaan

Sign In or Register to comment.