Property Change Script

I currently have a property change script that edits the name of a prop, but the issue is that I only want this script to run once. Any ideas on how to achieve this?

Your expected sequence of events isn't clear, nor is your intended result. Could you provide some more insight into exactly what it is you're trying to do?

I have a property change script bound to a prop (it's a simple script that changes a string to something more useful to the user) and I want this script to only execute one time, so that the user is able to overwrite this string. Currently, the script runs every time a change occurs, and I want it to only run on the first change. My intended result is the script iterates once.

The easiest way to manage this is to use a separate property which acts as a flag. It's best to modify the structure of your existing property such that is an object, but this could also be done with two sibling properties.

myString: {
    value: "original",
    hasChanged: False
}

Now modify your change script:

if not self.custom.myString.hasChanged:
    self.custom.myString.value = "new"
    self.custom.myString.hasChanged = True

This will result in the value changing only once before being locked. Note that these are ephemeral properties, and live only as long as the resource does. If you need something more permanent, you'll need to look into using tags or a database implementation along the same lines.

1 Like

I think you mean, "that edits the text property of a component". Editing the name of a property doesn't make sense as the user would never see it if it were even possible.

Wouldn't it be simpler and more obvious to the user to use a button for this ?

This was really helpful, thanks.

I've been trying to do this, but when I try to add a new property value (i.e. hasChanged) via a script to a start up event it doesn't show up in the Property Editor. I then I try to manually add a new value, and get an error saying "Property 'hasChanged' has not been defined and the schema does not allow additional properties."

No, a button would be unintuitive for what I'm doing.

Create the custom property manually. Then change it by script. Here I've added @cmallonee's code to the button's Events | onActionPerformed | Script.

Button hasChanged

As I mentioned, I'm unable to add a custom property manually, without getting the error "Property 'hasChanged' has not been defined and the schema does not allow additional properties."

That sounds like a problem with the JSON.
myString should be an object type.
Right-click on custom.myString | Structure | Change to and check that it has been declared as an object.

Make sure you're creating your own properties in the "CUSTOM" scope, not within one of the system defined areas like props or meta.

2 Likes

The PROPS, POSITION, and META categories have a prescribed set of properties which are allowed and the structure of those properties is more-or-less locked. The CUSTOM category is the only area you may define your own properties.

1 Like