HowTo read inst var of a parsed object in Behaviour?

0 favourites
  • 3 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • Hi

    I have made a behaviour where I am parsing an object as a variable.

    This object has many instance variables that I need to read in my script

    I tried to read the instance variables as if they were x,y,opacity variables ...etc, but it is not working.

    This is what I am trying:

    Acts.prototype.MyFunction= function (object_){
    
          var inst_only = object_.getCurrentSol().getObjects();
          inst_only = inst_only[0];
          console.log(inst_only.x); // it is working, I can see my x position in console
          console.log(inst_only.MyInstanceVariable); //NOT working, giving me undefined.
          ...[/code:28unziqc]
    
    I am stuck with my project at this stage, your help is highly appreciated.
    
    thanks
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I think I got the answer, from a similar thread:

    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:i5d6xxj2]
    
    will report back if it works
    
    EDIT:
    confirmed, and it is best used in a separate call function
  • Hi again

    could someone please help me. the code for parsing the object variables is only working in browser but not in Android Cordova emulator on intel XDK nor on actual android mobiles!

    could someone please have a look:

    		this.inst.update_bbox();
    
    		var inst_only = object.getCurrentSol().getObjects();
    		inst_only = inst_only[0];
    		
    			var varStr = "MyVariable";
    			var instIndex = 0;
    			var varIndex = -1;
    			var inst_only = object.getCurrentSol().getObjects();
    			inst_only = inst_only[0];
    			var instVarNames = inst_only.instance_var_names;
    			
    			var retvar;
    			for(var instVarNameIndex in instVarNames)
    			{
    			   if(instVarNames[instVarNameIndex] == varStr)
    			   {
    				   varIndex = instVarNameIndex;
    				   retvar = inst_only.instance_vars[varIndex];
    				   
    			   }
    			}[/code:2je6bcka]
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)