Unable to find object
by Matthew W · in Torque Game Engine · 04/12/2008 (12:22 am) · 6 replies
This is an error i've been getting that i dont understand (while working with this resource: qid=14265).
In Commander.cs of that resource i've copied:
And i thought it could be fixed by searching for 'onRightMouseDown' and then finding out how they called the function and what object they used. But that didn't work out.
I've been stuck here for a few days; this error message has also happened in other places. Do you know how to make this error go away?
In Commander.cs of that resource i've copied:
%pos = %this.getMouse3DPos();from function Commander::onRightMouseDown to function Commander::onLeftMouseDown. But, it gives me this error:
Unable to find object: ' ' attempting to call function 'getMouse3DPos'
And i thought it could be fixed by searching for 'onRightMouseDown' and then finding out how they called the function and what object they used. But that didn't work out.
I've been stuck here for a few days; this error message has also happened in other places. Do you know how to make this error go away?
#2
04/26/2008 (6:56 pm)
How can i find out what they're calling it with by using echos?
#3
Better yet, use an IDE like Torsion to put a break point in the Commander::onLeftMouseDown function, and then step back and where it is being called from, and why.
04/26/2008 (7:31 pm)
Echo writes text to the console. Use echo in places where this might be called to find out what values it is being called with, and/or where it is being called erroneously.Better yet, use an IDE like Torsion to put a break point in the Commander::onLeftMouseDown function, and then step back and where it is being called from, and why.
#4
To maybe clarify this a bit: a method is a special type of function that is called *on* an object. This object (usually called received) is what the special variable %this inside the method definition refers to. To bind this object, a variant of a call expression called 'dot notation' is used, like in
Here myObject gets bound to %this inside myMethod.
04/26/2008 (7:44 pm)
Are you using the snippet you have pasted inside some method?? If not, %this is not meaningful and thus will not be bound to an object.To maybe clarify this a bit: a method is a special type of function that is called *on* an object. This object (usually called received) is what the special variable %this inside the method definition refers to. To bind this object, a variant of a call expression called 'dot notation' is used, like in
myObject.myMethod( myArguments );
Here myObject gets bound to %this inside myMethod.
#5
@Rene: i'm not working on that particular code right now, but i have the same problem - unable to find object. Well, i guess my problem is that im unsure how to make an object in torque script. The only way i've noticed to get an object is to be inside a method and have it passed to you; i have to find objects to use and i dont know how to find them.
04/26/2008 (8:52 pm)
@Lee: can you use breakpoints in Codeweaver? i've never used them before.@Rene: i'm not working on that particular code right now, but i have the same problem - unable to find object. Well, i guess my problem is that im unsure how to make an object in torque script. The only way i've noticed to get an object is to be inside a method and have it passed to you; i have to find objects to use and i dont know how to find them.
#6
1) Have it be passed to you in a function or method (you already know this one).
2) Grabbing a variable (local or global) that stores the name or Sim ID of the object.
3) Using the Name of the object (I call this "direct reference")
All Sim Objects have a "global" scope in Torque Script, as far as the Client-Server barrier goes, if referenced by Name. All Client-side objects are available globally from the Client, and all Server-side objects are available globally on the Server. This means that if you Name an object, you can access that object by name at any time, within any function. For example:
This means that if you call an object "Foo" no other object can ever be called "Foo." Not a Player, StaticShapeData, any GUI, or Group... anything. I really can't stress this enough because it really trips people up. If you happen to accidentally reuse an object name, the one that is created "later" by the engine will "clobber" the previous one and you will never again be able to access the first object by name.
To avoid accidental Name reuse, it's probably a good idea to develop a Name prefix or suffix system. Give all your datablocks the suffix "_Datablock" for instance.
Hope this is the information you were looking for.
04/28/2008 (1:46 pm)
There are a few ways to acquire an object reference in Torque Script:1) Have it be passed to you in a function or method (you already know this one).
2) Grabbing a variable (local or global) that stores the name or Sim ID of the object.
3) Using the Name of the object (I call this "direct reference")
All Sim Objects have a "global" scope in Torque Script, as far as the Client-Server barrier goes, if referenced by Name. All Client-side objects are available globally from the Client, and all Server-side objects are available globally on the Server. This means that if you Name an object, you can access that object by name at any time, within any function. For example:
new ScriptObject(Foo);The Name of an object is the part between the parenthesis ( ). After the code above executes, methods and properties of that object can be accessed within any function simply by using its name as a reference:
Foo.bar();This method is safer than hard-code Sim ID's because Torque guarantees that the object Name will be the same each time the game runs, even if the Sim ID of the object is different. The only "gotcha" to object Names is that they must be 100% unique in the entire game, regardless of object type.
This means that if you call an object "Foo" no other object can ever be called "Foo." Not a Player, StaticShapeData, any GUI, or Group... anything. I really can't stress this enough because it really trips people up. If you happen to accidentally reuse an object name, the one that is created "later" by the engine will "clobber" the previous one and you will never again be able to access the first object by name.
To avoid accidental Name reuse, it's probably a good idea to develop a Name prefix or suffix system. Give all your datablocks the suffix "_Datablock" for instance.
Hope this is the information you were looking for.
Torque Owner Lee Latham
Default Studio Name
Try finding all the places this function is called, and then put some echo's in there to find out what they're calling it with. Better yet, use a script IDE like Torsion to simply trace it back.