Page 1 of 1

SFSObject Get Values?

Posted: 19 Dec 2022, 01:35
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

Re: SFSObject Get Values?

Posted: 19 Dec 2022, 08:23
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.

Re: SFSObject Get Values?

Posted: 19 Dec 2022, 18:30
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