- Home /
Send Message Overload
I'm trying to overload a method... something like:
function Blah () { Debug.Log("Do Something"); }
function Blah (string : String) { Debug.Log("Do Something and using that String"); }
and I'm calling as: SendMessage ("Blah"); SendMessage ("Blah", "Hello");
If I put Blah() in first place at my code, I receive two "Do Something" message. But if I put Blah(string:String) in first place, I receive one "Do Something and using that String" and one error: missing 1 argument.
What's happening? SendMessage don't support overloaded methods or I missed something?
I've recently been trying this too. Going to have to assume yes, Send$$anonymous$$essage does not support overloads. Whats strange to me however, is that it would choose to use the function that requires an argument over the function that does not... maybe it's something to do with Send$$anonymous$$essage only supporting 1 argument.
Answer by Caiuse · May 25, 2012 at 09:22 AM
Quick solution:
function myFunction(args : Hashtable){
var myString = args["myString"];
if(myString){
print("function with custom string "+myString);
} else {
print("function without string");
}
}
you will always have to provide a hashtable as an argument, but just use emptyHash = new Hashtable();