getSelectionSiz"> ConsoleMethod not able to return SceneObject? | Torque Game Engine | Forums | Community | GarageGames.com

Game Development Community

ConsoleMethod not able to return SceneObject?

by Justin Mosiman · in Torque Game Engine · 10/08/2006 (4:38 pm) · 5 replies

I am trying to return an object of class SceneObject from within ConsoleMethod, but when I try to compile I am getting lots of errors.

Here's my code:
ConsoleMethod( GuiRTSTSCtrl, getSelected, SceneObject, 2, 2, "")
{
   if(object->getSelectionSize() != 1)
      return 0;
   return object->getSelectedObject(0);
}
object->getSelectedObject(0) is defined as SceneObject *GuiRTSTSCtrl::getSelectedObject(U32 Index);

When I try to compile, I get:
Quote:
1>guiRTSTSCtrl.cc
1>..\engine\game\rts\guiRTSTSCtrl.cc(514) : error C2059: syntax error : ')'
1>..\engine\game\rts\guiRTSTSCtrl.cc(514) : error C2065: 'conmethod_return_SceneObject' : undeclared identifier
1>..\engine\game\rts\guiRTSTSCtrl.cc(514) : error C2146: syntax error : missing ';' before identifier 'cGuiRTSTSCtrlgetSelected'
1>..\engine\game\rts\guiRTSTSCtrl.cc(514) : error C2664: 'ConsoleConstructor::ConsoleConstructor(const char *,const char *,StringCallback,const char *,S32,S32)' : cannot convert parameter 3 from 'SceneObject (__cdecl *)(SimObject *,S32,const char **)' to 'StringCallback'
1> Incompatible calling conventions for UDT return value
1>..\engine\game\rts\guiRTSTSCtrl.cc(517) : error C2664: 'SceneObject::SceneObject(const SceneObject &)' : cannot convert parameter 1 from 'int' to 'const SceneObject &'
1> Reason: cannot convert from 'int' to 'const SceneObject'
1> No constructor could take the source type, or constructor overload resolution was ambiguous
1>..\engine\game\rts\guiRTSTSCtrl.cc(518) : error C2664: 'SceneObject::SceneObject(const SceneObject &)' : cannot convert parameter 1 from 'SceneObject *' to 'const SceneObject &'
1> Reason: cannot convert from 'SceneObject *' to 'const SceneObject'
1> No constructor could take the source type, or constructor overload resolution was ambiguous

Thanks for the help.

#1
10/08/2006 (4:40 pm)
Try:

ConsoleMethod( GuiRTSTSCtrl, getSelected, S32, 2, 2, "")
{
   if(object->getSelectionSize() != 1)
      return 0;
   return object->getSelectedObject(0)->getId();
}
#2
10/08/2006 (4:47 pm)
Thanks for the very quick reply. Can I not return a SceneObject? The reason that I want to return the SceneObject is so that I can switch camera views with the selected object, such as

%control = %client.getControlObject();
   %control = %playerId;
But if I return the Id, the camera doesn't change to the view of the player, it just stays the same.

Thanks.
#3
10/08/2006 (5:25 pm)
No, you can not return a sceneObject. Even if you could, the script engine would not understand it either. When accessing the camera in script, you access it by sending the ID to find () and then it runs whatever it needs on that sceneObject in the engine.

Scripts are always strings, remember that.
#4
10/08/2006 (5:47 pm)
Where can I find the find function? Something like
%player = find(%playerId);
   %control = %player;

Produces an error. What do you mean by "it runs whatever it needs on that sceneObject in the engine."? What I want to do is if I have the id of the object, I want the camera to switch to the camera of that player.
#5
10/09/2006 (7:30 am)
You didn't get it. The engine uses Sim::find() in C++ whenever you adress something by ID.

In script you can only access objects by ID or name. There are no such things as pointers or references.

Re-writing your example:

%control = %playerId;

All console methods which are supposed to take objects as inputs do so by taking IDs, and then using those IDs in C++ to locate the appropriate object.