Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Converting a C# script to Javascript, sytanx question!

Discussion in 'Scripting' started by rmele09, Jun 9, 2014.

  1. rmele09

    rmele09

    Joined:
    Nov 8, 2010
    Posts:
    688
    Hey guys I am trying to convert a uLink C# script to javascript, and I hit a snag with the functions below. I believe the error is in the parameter part of the function, I think the syntax is incorrect. Any idea how one would write these correctly?
    Code (JavaScript):
    1. function uLink_OnPlayerDisconnected(uLink.NetworkPlayer player)
    2.     {
    3.     uLink.Network.DestroyPlayerObjects(player);
    4.     uLink.Network.RemoveRPCs(player);
    5.     }
    6.    
    7. function uLink_OnFailedToConnect (uLink.NetworkConnectionError error)
    8.     {
    9.     Debug.LogError("uLink got error: "+ error);
    10.     }
    11.    
    12. function uLink_OnPlayerConnected(uLink.NetworkPlayer player)
    13.     {
    14.     Debug.Log("Player connected from " +player.ipAddress + ":" + player.port);
    15.     }
     
  2. rmele09

    rmele09

    Joined:
    Nov 8, 2010
    Posts:
    688
    I forgot to mention the error, it is Unexpected Token.
     
  3. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    When reporting the error it is important to report the whole error.

    In this case, you need to replace function with void.

    EDIT: Ignore, thought it was UnityScript -> C#
     
    Last edited: Jun 10, 2014
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,398
    No, the question is about converting C# to Unityscript. In any case, the syntax for Unityscript variables is "name : type", compared to C# which uses "type name".

    --Eric
     
    DanielQuick likes this.
  5. DanielQuick

    DanielQuick

    Joined:
    Dec 31, 2010
    Posts:
    3,137
    Ah, whoops! Glad you caught that.
     
  6. rmele09

    rmele09

    Joined:
    Nov 8, 2010
    Posts:
    688
    Oh gotya so like this :
    1. function uLink_OnPlayerDisconnected(player : uLink.NetworkPlayer)

    No more errors, thanks a lot Eric and Daniel!