Game Development Community

Calling from C++ Code using Torque Script?

by Alan Murphy · in Technical Issues · 05/21/2009 (9:45 am) · 4 replies

Hi guys! Is it possible to call c++ code using torque script and if so how might I go about it? I just want to extract some information thats all! Thanks!

#1
05/21/2009 (10:37 am)
Export the method with ConsoleMethod(). There are numerous examples of this in the source, easily found once you know what string to grep for. :-)
#2
05/24/2009 (3:00 pm)
Thanks for your reply... So If I have a function in my c++ code called say functionX() with no parameters which returns a floating point number in a class called ClassX; would it then be correct to put in my script, wherever I want to use the floating point number returned, the following

ConsoleMethod (ClassX, functionX, float, 2,2,"()")
{
object->functionX();
}

The return type of functionX will be a floating point number but does the consoleMethod have a return type? If I understand it correctly I am using the console method to call functionX but where will the floating point number that functionX returns be returned to or how can I assign it to a variable in my script that I could work with? Is there a way to extract the value that functionX returns from ConsoleMethod? Can I assign the value inside ConsoleMethod as you would in normal code like this...

%variable=functionX() ??

Basically I am just trying to save the value that functionX would return to a variable in script!

Sorry if my questions seem basic I am a beginner! Thanks! :)
#3
05/24/2009 (4:53 pm)
You're getting close. First off, within Torque, floats are defined as F32, so that would be your return type in the ConsoleMethod. Also, your ConsoleMethod needs to return a value, so you would do something like:

ConsoleMethod (ClassX, functionX, F32, 2,2,"()")
{
   return object->functionX();
}

To call this within script, you would first have an object of type ClassX. Then it would be a simple %object.functionX() call. In your example, that would be %variable=%object.functionX();
#4
05/24/2009 (4:59 pm)
Thanks Justin, I will give this a go! :)