SFSObject Get Values?

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

Post Reply
User avatar
IdleChimp
Posts: 10
Joined: 19 Dec 2022, 01:00

SFSObject Get Values?

Post by IdleChimp »

I am tired of looking at this one. I looked at it on the server-side extension end, and everything is sending properly from the client, but something is wrong--obviously, or I wouldn't be here. Just look at the code. It has to be something simple. Tired eyes! Tired eyes...


Extension request:

Code: Select all

        SFSObject data = new SFSObject();
        data.PutInt("id", id);
        data.PutDouble("x", px);
        data.PutDouble("y", py);
        data.PutDouble("z", pz);
        data.PutDouble("r", ry);
        NIMSPRO.SFS.Send(new ExtensionRequest("transform", data));


Extension response:

Code: Select all

        SFSObject t = (SFSObject)param.GetSFSObject("transform");
        int id = t.GetInt("id");
        var px = (float)t.GetDouble("x");
        var py = (float)t.GetDouble("y");
        var pz = (float)t.GetDouble("z");
        var ry = (float)t.GetDouble("r");
Thanks so much,
IdleChimp
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: SFSObject Get Values?

Post by Bax »

Hello.
Not sure what the problem is... are you having issues retrieving the parameters on the server side?
If yes, it looks like you are expecting an object with the name of the request containing your parameters. This is wrong.
Your parameters are directly contained in the params object, so:

Code: Select all

	int id = params.getInt("id");
	float px = (float) params.getDouble("x");
	float py = (float) params.getDouble("y");
	float pz = (float) params.getDouble("z");
	float ry = (float) params.getDouble("r");
Note that you are using Java on the server side, so method names start with a lowercase letter.
Paolo Bax
The SmartFoxServer Team
User avatar
IdleChimp
Posts: 10
Joined: 19 Dec 2022, 01:00

Re: SFSObject Get Values?

Post by IdleChimp »

I figured it out. Just a dumb error on my part. I wasn't putting the data into an SFSObject with the appropriate name and then sending it to the clients.
It was a server side extension flub in my very simple code. Like I said, tired eyes! Thanks.

Here, just incase someone pulls a dumb one like me:

Fixed extension request:

Code: Select all

    //----------------------------------------------------------------------
    //  CLIENT REQUEST
    //----------------------------------------------------------------------
    @Override
    public void handleClientRequest(User sender, ISFSObject data)
    {
        Room room = sender.getLastJoinedRoom();
        List<User> userList = GetOthersList(room, sender);
        
        ISFSObject response = new SFSObject();
        response.putSFSObject("transform", data);
        
        // Send back 
        send("transform", response, userList, false);
     }
I used the same name for the SFSObject and CMD just to keep things straight. Works fine now!
Smacking myself. LOL
Post Reply