Returning Strings and stuff.....
by Ricky Taylor · in Torque Game Builder · 11/06/2005 (1:31 pm) · 5 replies
1) How do I return a string in a ConsoleMethod. If I can't is there another way of storing and getting the string.
2) How do I interpret a class thats passed as an argument?
Thanks in advanced,
Ricky,
2) How do I interpret a class thats passed as an argument?
Thanks in advanced,
Ricky,
#2
Ive worked out the class thing. =)
11/06/2005 (3:10 pm)
I have looked, there doesnt appear to be a way of returning strings, which I found odd, so I posted here hoping I was wrong.Ive worked out the class thing. =)
#3
that's how its done (I think):
ConsoleMethod( SomeClass, getSomeValue, const char*, 2, 2, "")
{
char* buffer = Con::getReturnBuffer( dStrlen( object->mSomeValue)+1 );
dStrcpy(buffer, object->mSomeValue);
return buffer;
}
- Michael
11/06/2005 (3:48 pm)
Hi Ricky,that's how its done (I think):
ConsoleMethod( SomeClass, getSomeValue, const char*, 2, 2, "")
{
char* buffer = Con::getReturnBuffer( dStrlen( object->mSomeValue)+1 );
dStrcpy(buffer, object->mSomeValue);
return buffer;
}
- Michael
#4
(1) has been answered above.
(2) You can use "Sim::findObject( id )". "findObject" has many overloads but by far the easiest way is to just directly passing the incoming string parameter (which is an id). Look in "fxSceneObject2D.cc" (line 505) e.g. the "addToScene()" function. Here the incoming ID is in argv[2] and uses...
The dynamic_cast will obviously let you know if the object is what you expect.
For more examples, search for the "Sim::findObject" call in the SDK.
If you need to pass an object id back, set the return type as S32 (which is the type for SimObjectId) and just return "myObject->getId()".
Hope this helps,
- Melv.
11/07/2005 (5:32 am)
Ricky,(1) has been answered above.
(2) You can use "Sim::findObject( id )". "findObject" has many overloads but by far the easiest way is to just directly passing the incoming string parameter (which is an id). Look in "fxSceneObject2D.cc" (line 505) e.g. the "addToScene()" function. Here the incoming ID is in argv[2] and uses...
fxSceneGraph2D* pSceneGraph2D = dynamic_cast<fxSceneGraph2D*>(Sim::findObject(argv[2]));
The dynamic_cast will obviously let you know if the object is what you expect.
For more examples, search for the "Sim::findObject" call in the SDK.
If you need to pass an object id back, set the return type as S32 (which is the type for SimObjectId) and just return "myObject->getId()".
Hope this helps,
- Melv.
Torque Owner Jason Swearingen
1b) You can store your string as a global variable, which is accessable wherever.
2) you have to use the simObject functions, i dont remember the exact functions but various consolefunctions/consolemethods take the object name as a parameter (which is just a string) and then get the actual object.
your best bet is to look at the C++ source for the answers/examples you need.