Function overloading
by praju · in Torque Game Builder · 08/04/2010 (7:06 am) · 5 replies
Hi guys,
How do you do function overloading in TGB????
Eg( in c++) : void scale(int value);
void scale(Vector 2D);
I need the functions in TGB. One takes a normal value like integer and the other takes a vector.
I hope it makes sense.
Thanks in advance!!
How do you do function overloading in TGB????
Eg( in c++) : void scale(int value);
void scale(Vector 2D);
I need the functions in TGB. One takes a normal value like integer and the other takes a vector.
I hope it makes sense.
Thanks in advance!!
About the author
#2
If you don't mind me asking, why do you want to overload a function like this? Why not just write 2 separate functions?
08/04/2010 (8:10 am)
Here's an okay way to do it:function scaleValue( %value )
{
%numWords = getWordCount( %value );
if( %numWords == 1 )
{
return %value * 5;
}
else if( %numWords == 2 )
{
return t2dVectorScale( %value, 5 );
}
else
{
error( "scaleValue error: invalid input [" @ %value @ "]" );
}
}If you don't mind me asking, why do you want to overload a function like this? Why not just write 2 separate functions?
#3
@Williams: I usually code in C++!! So i just wanted to put my C++ code into TGB script, thats all!! Sure, i can write two separate functions, but just wanted to know whether TGB script supported it!!! Anyways thanks for your input..!:)
08/04/2010 (8:43 am)
Thanks guys!!! @Williams: I usually code in C++!! So i just wanted to put my C++ code into TGB script, thats all!! Sure, i can write two separate functions, but just wanted to know whether TGB script supported it!!! Anyways thanks for your input..!:)
#4
08/04/2010 (8:33 pm)
You just have to remember that all parameters in torquescript functions are actually strings. That's why function overloading can't work.
Torque Owner Aditya Kulkarni
Loon Games
1) Attach a class to a function
function className::func() { }2) Packages
package packageName1 { function func() { } }; package packageName2 { function func() { } };Now activate the package that you want to use.