On property changed

For developers using the Construct 2 Javascript SDK

Post » Thu Jun 26, 2014 8:50 pm

I'm trying to figure out how to change all instance properties to the initial(instance 1) settings. I want to make sure that the properties remain the same across all instances. Here is what I have at the moment, any ideas?

this setting sets the values to an [object][object] error.

IDEInstance.prototype.OnPropertyChanged = function(property_name)
{

this.properties["App ID"] = property_list[0];
this.properties["Language"] = property_list[1];
}

To better explain, I effectively only want to allow users to change the values on the first instance. I'd prefer to set the read only flag for the rest, but I can't seem to wrap my mind around it at this moment.
www.h1k3.tech

We are here for you!
B
87
S
22
G
16
Posts: 715
Reputation: 16,785

Post » Thu Jun 26, 2014 10:18 pm

try this
Code: Select all
var pluginInstances = {}; //This will store your plugin instances.
var pluginInstancesIndex = 0; // A Simple index counter

function IDEInstance(instance, type)
{
    assert2(this instanceof arguments.callee, "Constructor called as a function");

    this.instance = instance;
    this.type = type;
    this.properties = {};

    pluginInstances[pluginInstancesIndex++] = this.properties; // Add this to store the new properties instances to the colleciton

    for (var i = 0; i < property_list.length; i++)
        this.properties[property_list[i].name] = property_list[i].initial_value;

}

IDEInstance.prototype.OnPropertyChanged = function(property_name)
{
    //When the property changes get the val
    var val = this.properties[property_name]
    for(var i in pluginInstances){
            //Then loop through the instances and apply it to all
       pluginInstances[i][property_name] = val;
    }
}

B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Thu Jun 26, 2014 10:44 pm

That looks pretty elegant and simple. Thanks I will try that. Any idea how to set the .readonly flag?
www.h1k3.tech

We are here for you!
B
87
S
22
G
16
Posts: 715
Reputation: 16,785

Post » Thu Jun 26, 2014 10:49 pm

Not really.. I don't have much experience with plugin properties yet. But I don't think properties have read-only setting (could be wrong)... but it would kind of defeat the purpose i think of something the user is intended to be able to change that is set to read only.
B
20
S
7
G
1
Posts: 221
Reputation: 2,077

Post » Thu Jun 26, 2014 11:10 pm

Yeah, it's listed in the manual, anywho thanks much :)
www.h1k3.tech

We are here for you!
B
87
S
22
G
16
Posts: 715
Reputation: 16,785


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests