Page 1 of 1

Where does the object go to?

Posted: 19 Dec 2010, 14:52
by Georgie
If i send this from the server

send("add", resObj, sender);

How do i then get the resObj in unity?

Posted: 19 Dec 2010, 17:22
by ThomasLund
I dont think thats really a valid use of the send method.

What you do is e.g.

smartFox.Send( new ExtensionRequest("MyExt", parameters) );
or
smartFox.Send( new JoinRoomRequest("Lobby") );

So you send one of the request classes

/Thomas

Posted: 19 Dec 2010, 17:22
by appels
in the OnExtensionResponse handler :

Code: Select all

	private void OnExtensionResponse(BaseEvent evt) {
		try {
			string cmd = (string)evt.Params["add"];
			ISFSObject dt = (SFSObject)evt.Params["params"];

Posted: 19 Dec 2010, 18:29
by ThomasLund
Argh - very true. I should slow down when reading. You said from server->client and not client->server. Sorry.

OnExtensionResponse is the right answer yes. Dont forget to subscribe to the callback.

/Thomas

Posted: 19 Dec 2010, 21:00
by Georgie
ThomasLund wrote:Argh - very true. I should slow down when reading. You said from server->client and not client->server. Sorry.

OnExtensionResponse is the right answer yes. Dont forget to subscribe to the callback.

/Thomas
he he, yes I got it from the docs :D

Posted: 19 Dec 2010, 21:21
by Georgie
Is there anything else I need to do?

this codes not being executed

public void OnExtensionResponse(BaseEvent evt) {

string cmd = (string)evt.Params["cmd"];
SFSObject dataObject = (SFSObject)evt.Params["params"];

Debug.Log(cmd);
}

I'm managing to send to the server and do a trace, so I know that much is working, but the debug statment for the returned values is not being triggered.

Posted: 20 Dec 2010, 00:31
by tchen
Checklist:

Did you include

Code: Select all

m_sfs.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse);
somewhere during init?

Posted: 20 Dec 2010, 06:53
by appels
you need to register for the callback so the API knows where to send the message.

Posted: 20 Dec 2010, 08:30
by Georgie
Yeah sorry I had missed that.

Is there a way to send different events from the server to different functions?

Like one for "add" one for "subtract"? or do they all have to go to 1 function and use logic?

--

Also server side, is there a short hand way to do SEND to all users in room etc?

One more

Is there a list of all users in the room ready built in? if so how do i access it?

Posted: 20 Dec 2010, 16:23
by dragagon
You can do one of two things, either you can add multiple if/else blocks so like

Code: Select all

public void OnExtensionResponse(BaseEvent evt) { 

    string cmd = (string)evt.Params["cmd"]; 
    SFSObject dataObject = (SFSObject)evt.Params["params"]; 

    if(cmd == "add")
    {
       // add
    }
    else if(cmd == "subtract")
    {
     //subtract
    }
    Debug.Log(cmd); 
} 
Or you can do like my blog tutorial does and sets up a handler.

Code: Select all

        try
        {
            string cmd = (string)evt.Params["cmd"];
            ISFSObject dt = (SFSObject)evt.Params["params"];

            ExtensionHandler handler;

            if (handlers.TryGetValue(cmd, out handler))
            {
                handler(dt);
            }
            else
            {
                Debug.LogError("Got unhandled cmd: " + cmd);
            }
        }
        catch (Exception e)
        {
            Debug.Log("Exception handling response: " + e.Message + " >>> " + e.StackTrace);
        }
My personal preference is to use the handler so that I don't have a giant list of message types.

Posted: 20 Dec 2010, 17:13
by appels
yep, you can send anything and use cmd to extract them on the client side in the OnExtensionResponse handler.

Posted: 20 Dec 2010, 19:23
by ThomasLund
Handler pattern is my personal favorite too. And it will also be "similar" to how things look on the server. So double bonus of less cluttered code and less differences on both ends