Search Unity

Sendmessageupwards from JS to C#??

Discussion in 'Scripting' started by Meltdown, Apr 12, 2012.

  1. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822
    It's been a while since I've had to convert some code from js to C# so I have an EnemyDamageReceiverC.cs script attached to my enemy.

    Yet when my .js file that detects if any damage was taken calls this line...

    Code (csharp):
    1. hit.collider.SendMessageUpwards("ApplyDamage", sendArray, SendMessageOptions.DontRequireReceiver);
    I get told MissingMethodException: The best match for method ApplyDamage has some invalid parameter.

    I have my C# script in ScriptsDB under standard assets, and the method is marked as public, so why is the JS not finding this method on my object?
     
  2. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,830
    Read the error message again:

    "MissingMethodException: The best match for method ApplyDamage has some invalid parameter."

    It found the method, but the parameters didn't match up.
     
  3. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822
    AHA, thanks, after scrutinising the params again.. it came down to a typo lol..

    All I did was convert the line in the original .js file

    function ApplyDamage(Arr : Object[])

    to this in the C# file

    public void ApplyDamage(Object[] Arr)


    Forgot to change Object[] to object[] :eek:

    Oh my how I hate converting JS code, not my strong point.
     
  4. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,830
    As much as I say it, that's a unity 'bug' - whoever thought it would be a good idea to create a base class called Object needs to be shot.
     
  5. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822
    +1
     
  6. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822
    You know what I would rather have... is them removing js and boo and only allow coding in C#.
    It would be a great standard. all tutorials focused on C#, all people speaking one language.

    Of course it's not going to happen but it would be nice
     
  7. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,830
    I might be able to support getting rid of US - there's very little to nothing it does well and there is a bunch of things it doesn't do well that among other things hurt the API.

    Boo on the other hand offers a different paradigm, and has nifty features like CaaS which would be awesome to use. What it needs is more tutorials etc into how to use it, rather than relying upon prior Python knowledge.

    Just providing an interesting tid-bit, if someone wnats to continue I suspect a new thread would be order - one with a very carefully written OP.
     
  8. Meltdown

    Meltdown

    Joined:
    Oct 13, 2010
    Posts:
    5,822