- Home /
Using SmartFoxServer with Javascript instead of c#
I am using Javascript for my project in Unity and would like to be able to connect to SFS using Javascript as well. I've been trying to convert the SFS example to Javascript, but since I have never used C# this is proving problematic. I've gotten most of the errors out, but I am still having issues with this block:
import SmartFoxClientAPI;
private var serverName : String = "127.0.0.1"; private var serverPort : int = 9339; private var statusMessage : String = "";
function Start() { var smartFox : SmartFoxClient = new SmartFoxClient(); SFSEvent.onConnection += HandleConnection; smartFox.Connect(serverName, serverPort); }
I get the error "BCE0005: Unknown identifier: 'HandleConnection'." for this line:
SFSEvent.onConnection += HandleConnection;
@James, just FYI, if you do part of your project in C# and part in JS: http://answers.unity3d.com/questions/3392
Answer by burnumd · Apr 05, 2010 at 07:44 PM
SFSEvent.onConnection is a delegate, a feature which is not currently supported in Unity's Javascript. To attain an equivalent effect in Javascript, you'd need to convert SFSEvent.cs in the SmartFox source (SFS_CSharp/API/sources/SmartFoxClient) to JS. All of the delegates in there would need to be converted to a list or some other structure to which you would add functions that match the signature of the delegate. Anywhere those delegates are called, you would need to iterate through the list, calling those functions.
So in other words, I should just go ahead and do the connection part of my game in C#?
That's probably the easiest way. I got about as far as you did before deciding this approach wasn't worth it :).