Game Development Community

About access behavior field throught referenced object

by Michele Condo' · in iTorque 2D · 03/19/2011 (1:00 pm) · 1 replies

Hello!

I've a question.
I made a behavior, with some fields, like "speed" and "angularSpeed".

Inside a behavior I need only call %this.speed and %this.angularSpeed to access.
But I need to access to this fields outside behavior, from a referenced object, picked via touches, like follow:

function oniPhoneTouchDown(%touchCount, %touchX, %touchY) {
        %curX = getWord(%touchX, 0);
        %curY = getWord(%touchY, 0);
	%worldPos = sceneWindow2D.getWorldPoint( %curX SPC %curY );

   	%scenegraph = sceneWindow2D.getSceneGraph();  
   	%objects = %scenegraph.pickPoint(%worldPos.x, %worldPos.y);  
   	for (%i = 0; %i < getWordCount(%objects); %i++) {  
      	      %object = getWord(%objects, %i);  
      	      if (%object.getName() $= "itemToFind") {
      	           $itemObj = %object;

                   %localSpeed = $itemObj.speed;  // here
      	           break;
   	      }
	}
}

But using this (see "here" line) cannot access the variable speed, xcode give me error.

I trying also to find the behavior and call a behavior method that return the variable, like this (inside the same function and I have only one behavior):

$behaviorPtr = $itemObj.getBehaviorByIndex(0);
%localSpeed = $behaviorPtr.getSpeed() // this make only a return of speed from behavior

But cannot access it.

Anybody can help me?

Tnx, bye!

#1
03/20/2011 (9:46 am)
Ahaah.. lol, sorry :)

Directly call not working, but using behavior pointer work very well.. I wrote the behavior method in wrong way, I had forgotten the %this parameter in the method sign xD

Sorry for useless post :D