x


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?

more ▼

asked Apr 08 '12 at 10:48 PM

fractyja gravatar image

fractyja
21 1 2 2

I've recently been trying this too. Going to have to assume yes, SendMessage 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 SendMessage only supporting 1 argument.

May 25 '12 at 09:15 AM Caiuse
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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();

more ▼

answered May 25 '12 at 09:22 AM

Caiuse gravatar image

Caiuse
787 83 102 121

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3444
x184
x157
x16

asked: Apr 08 '12 at 10:48 PM

Seen: 644 times

Last Updated: May 25 '12 at 09:22 AM