Custom Property#
Add a new custom Property to the parent Node.
import tosclib as tosc
if __name__ == "__main__":
root = tosc.load("docs/demos/files/test2.tosc")
parent = tosc.ElementTOSC(root[0])
# Set the property to the parent node, not the root node.
prop = tosc.Property("s", "CustomProperty", "Craig")
parent.createProperty(prop)
print("Added Property: ")
parent.showProperty("CustomProperty")
tosc.write(root, "docs/demos/files/customProp.tosc")
Then you can access that Property in Touch OSC Editor with .lua like this:
--This is lua code inside the touch osc editor--
function onValueChanged(key, value)
if key == "touch" and self.values.touch == true then
print(self.parent.CustomProperty)
self.parent.CustomProperty = self.parent.children.label2.values.text
end
end
Demo Files:
GIFS
Call script that changes the Custom Property, then call another one that sets the label text to the Custom Property.
Save and close the template. Then load it again and you’ll see the label text remains, as it sets its value to the Custom Property on init.
This is the lua code in the label#
function init()
self.parent.children.label3.values.text = self.parent.CustomProperty
end
function onValueChanged(key, value)
if key == "touch" and self.values.touch == true then
print(self.parent.CustomProperty)
self.parent.children.label3.values.text = self.parent.CustomProperty
end
end