How do I get instance of an object type in instance function, such as Instance.onCreate? I know there is a type.instances array, but how to sort the particular instance out?
Develop games in your browser. Powerful, performant & highly capable.
As an example say we wanted to check the Text value of each Text Plugin Object Type Instance. You could use this statement to access the value:
this.type.instances[index].text;[/code:2uk93qx3]If you look at the implementation of the Text Plugin, you'll find in the runtime.js that the Instance.onCreate has a 'text' member variable. If you wanted to look at the "Instance Variables" that you added at Edit Time you could use these statements: [code:2uk93qx3] var instIndex = 0; var varStr = 'text2';//made up instance variable added in the editor var varIndex = -1; var inst = this.type.instances[instIndex]; var instVarNames = inst.instance_var_names; for(var instVarNameIndex in instVarNames) { if(instVarNames[instVarNameIndex] = varStr) { varIndex = instVarNameIndex; } } var instVarValue = inst.instance_vars[varIndex]; [/code:2uk93qx3]
I'm not sure the question in the OP makes sense. You refer to the created instance with 'this'. If you want to refer to a different instance, then which are you after? You need to explain exactly what you're trying to do in detail.