[open] changing property of an item in a sketchpad at runtime
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
Hi,
It's not easy to change the contents of a
sketchpadby accessing the item in the way you're doing now. However, what you could do is create acanvasobject that is a copy of asketchpad, and work on that. For example, you could create a copy of mySketchpad and add a fixation dot like so:See also:
Does that help at all?
Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
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
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:
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!
I think that is actually a good solution, and quite easy to implement.
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
Check out SigmundAI.eu for our OpenSesame AI assistant!