Game Development Community

console: object can not be found

by rennie moffat · in Torque Game Builder · 01/25/2010 (5:00 pm) · 13 replies

Hi there,
I building this behavior where the owner must see an object and get its position. I have this function, however the console tells me it cannot find the "playerObject", tho I have it named in a behaviorfield and named subsequently in the editor.

If someone can tell me how to correct this that would be great.


function playerPickUpSomething::onUpdate()
{
%this.owner.getPosition(%this.playerObject);

if(%this.playerObject.position = %this.owner.position)
%this.owner.mount(%this.playerObject);
}

About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.


#1
01/25/2010 (5:51 pm)
Okay I am not so good with behaviors (to be honest, I don't ever need them for any of my games :D) but your function looks weird..

First, it is saying object not found because you haven't defined %this, you should have defined it in the parenthesis after onUpdate.

Second, you function is only going to work for an object with the class playerPickUpSomething, unless this is your class of your player it should be fixed.

Third, I am not to sure about this one but your

%this.owner.mount(%this.playerObject);

line should be in the form of this:

%obj.mount(t2dSceneObject, [offsetX / offsetY], [mountForce], [trackRotation?], [sendToMount?], [ownedByMount?] , [inheritAttributes?])

It should be something like this:

// Fix the class thing if it isn't the class of your player or the object your aiming on updating.
function playerPickUpSomething::onUpdate(%this)
{
   %this.owner.getPosition(%this.playerObject);

   if(%this.playerObject.position = %this.owner.position)
      %this.owner.mount(%this.playerObject);
}
#2
01/25/2010 (6:34 pm)
right, since there is no related class (owner and playerObject) so should I use a global or plug in the same class in the editor?

also if I leave out further "arguments" of a function like mount, will it automatically not work?

thanks.
#3
01/25/2010 (7:01 pm)
Well mount needs all the arguments to work, because without them how will it know where to mount to the object? how strong the force of the mount should be and so on?

About the class thing, this is how I would do it in these cases:

I am player my class is player and I have an object which I defined as my owner, there is another object out there which I defined as playerObject, I need to find it's position and check if my owners position is the same as the playerObject, if it is I'll mount them.

Now the code:

//Lets say I've done all the stuff which leads to onUpdate (like you have).

function player::onUpdate(%this)
{
   %ownerPosition = %this.owner.getPosition();
   %objPosition = %this.playerObject.getPosition);

   if(%ownerPosition == %objPosition)
   {
      %this.owner.mount(%this.playerObject, "0 0", 0, true, true, true, true);
   }
}

The mount line there just mounts it directly to the center of the owner object. That should get it to work.
#4
01/25/2010 (7:41 pm)
right,
Re: mount and its arguments I was thinking maybe presetting the link points in the editor would do it. Makes sense tho, I can get down with that.




right and thanks for the code.
I am just beginning coding and have had the last 2 weeks off because of a another project.





#5
01/25/2010 (7:42 pm)
So my skills are a little rusty.


Thanks!
#6
01/26/2010 (12:29 am)
No Problem, the best way to get all the mount info is within the editor, and then use that with code, it gives the best result.

- Houssen
#7
01/26/2010 (11:01 am)
Thanks again.


Ren
#8
01/26/2010 (11:29 am)
Hi there,
I have a game behavior which is supposed to mount to an objectA, if that objectB enters the prior objectAs area.

I gave the objectA the behavior, and objectB a behaviorField in that behavior, as below and named it jelly in the editor, then passed that into the behaviorfield for playerObject. But the console tells me that is it "unable to find object, attempting to call position".

%template.addBehaviorField(playerObject, "object which is mounted by owner", object, "", t2dSceneObject);

:? any insight would be greatly appreciated.

///it is here the consle says that it can not find or locate the position of the playerObject.
function playerPickUpSomething::onUpdate(%this)
{
	%ownerPos = %this.owner.getPosition();
	%jellyPos = %this.playerObject.getPosition();
}
#9
01/26/2010 (3:01 pm)
function pickUpLobster::onUpdate(%this)
{
	%ownerPos = %this.owner.getPosition();
	%lobsterPos = %this.lobster.getPosition();
		
	
	if(%ownerPos == %lobsterPos)
	%this.lobster.mount(%this.owner, %this.xMount, %this.yMount, %this.forceAmount, true, true, true, true);
//lobster was already defined as a behaviorField, as an t2dSceneObject. 
}

why wont this work?!
:(


My player in theory should slide right over my other object, lobster and therefore at some point, there two locations will be equal! However, my guy slides right over the lobster and it (the lobster) is not picked up.


What giveth?


#10
01/26/2010 (3:18 pm)
float point numbers and vectors (like positions in torque), cannot be compared with the equivalence operator.
use something like
%someThreshold = 0.01;
if(VectorDist(%ownerPos, %lobsterPos ) < %someThreshold)
#11
01/26/2010 (3:42 pm)
I did not realize that.


Thanks.


But how is this working....


if vectorDist is the distance between the two vectors I see they are subtracted from each other.




niiiiiice. thank you.


#12
01/26/2010 (3:51 pm)
I did that but My owner.. and its behavior (playerObject) still does not see or recognise the lobster.

It says in the console
"unable to find object ' ' attempting to call 'getPosition'





i have been having trouble with this all day too.
How do I get my owner to see/recognize a property, like position of another object?

I currently have the other object as a behaviorField (t2dSceneObject), named lobster, which I have named accordingly in the editor. I would have thought this should work.


:?
#13
01/26/2010 (3:52 pm)
///in my behavior template I have the field...
	%temlpate.addBehaviorField(lobster, "object to pick up", object, "lobster", t2dSceneObject);	
	
///I call it here.
function pickUpLobster::onUpdate(%this)
{
	%ownerPos = %this.owner.getPosition();
	%lobsterPos = %this.lobster.getPosition();
	///but it says it can not find this object, above, lobster...? and I have named it lobster in the editor.

	
}