Converting a C# script to Javascript, sytanx question!

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?

function uLink_OnPlayerDisconnected(uLink.NetworkPlayer player)
    {
    uLink.Network.DestroyPlayerObjects(player);
    uLink.Network.RemoveRPCs(player);
    }
   
function uLink_OnFailedToConnect (uLink.NetworkConnectionError error)
    {
    Debug.LogError("uLink got error: "+ error);
    }
   
function uLink_OnPlayerConnected(uLink.NetworkPlayer player)
    {
    Debug.Log("Player connected from " +player.ipAddress + ":" + player.port);
    }

I forgot to mention the error, it is Unexpected Token.

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#

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

1 Like

Ah, whoops! Glad you caught that.

Oh gotya so like this :

  • function uLink_OnPlayerDisconnected(player : uLink.NetworkPlayer)

No more errors, thanks a lot Eric and Daniel!