the order of user and room variable

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

User avatar
Wei
Posts: 50
Joined: 13 Jun 2017, 08:16

the order of user and room variable

Postby Wei » 03 Aug 2017, 22:40

Below is how I create user and room variables

Code: Select all

 List<UserVariable> vars = Arrays.asList
                (
                        new SFSUserVariable("seat", uid),
                        new SFSUserVariable("id", uid),
                        new SFSUserVariable("headurl", headurl),
                        new SFSUserVariable("nickname", nickname),
                        new SFSUserVariable("score", 0),
                        new SFSUserVariable("isLandlord", 0),
                        new SFSUserVariable("remain", 0)
                );
               
getApi().setUserVariables(theUser, vars);


Code: Select all

List<RoomVariable> vars = Arrays.asList
                (
                        new SFSRoomVariable("user1", uid),
                        new SFSRoomVariable("user2", 0),
                        new SFSRoomVariable("user3", 0),
                        new SFSRoomVariable("user4", 0),
                        new SFSRoomVariable("landlord", 0),
                        new SFSRoomVariable("facedown", 0),
                        new SFSRoomVariable("round", round),
                        new SFSRoomVariable("currentRound", 0),
                        new SFSRoomVariable("times", times),
                        new SFSRoomVariable("next", uid),
                        new SFSRoomVariable("ready", 1)
                );
               
cfg.setRoomVariables(vars);


I use below lines to get those variables on client side

Code: Select all

myself = sfs.MySelf;
theRoom = sfs.LastJoinedRoom;
      
roomVars = theRoom.GetVariables ();
userVars = myself.GetVariables ();


User variables are arranged in the same order on both server side and client side, but the order of room variables are different, the order of room variables on client side is

Code: Select all

user1
next
user2
currentRound
times
landlord
round
ready
facedown
user3
user4


Did I do anything wrong?

As you can see, I've set 11 room variables, if I want to change just 1 or 3 of them, what should I do?

Code: Select all

RoomVariable user2 = new SFSRoomVariable("user2", uid2);
getApi().setRoomVariables(null, theRoom, Arrays.asList(user2));


Code: Select all

RoomVariable user2 = new SFSRoomVariable("user2", uid2);
RoomVariable user3 = new SFSRoomVariable("user3", uid3);
getApi().setRoomVariables(null, theRoom, Arrays.asList(user2, user3));
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: the order of user and room variable

Postby Lapo » 04 Aug 2017, 08:03

Variables are handled as key/value pairs, so they are stored in a map like structure.
When you obtain a list of variables the resulting list does not keep a specific order.

There's nothing wrong with what you're doing, simply variables are not expected to be kept in any specific order.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: the order of user and room variable

Postby Lapo » 04 Aug 2017, 08:07

As you can see, I've set 11 room variables, if I want to change just 1 or 3 of them, what should I do?

Just change those that you need :)
If you want to change one variable ...

Code: Select all

UserVariable test = user.getVariable("test");
int value = test.getIntValue();

getApi().setUserVariables(user, Arrays.asList( new SFSUserVariable("test", value +1));


If you want to change more you just add more...

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
Wei
Posts: 50
Joined: 13 Jun 2017, 08:16

Re: the order of user and room variable

Postby Wei » 04 Aug 2017, 12:39

noted, we're translating all SFS2X docs into Chinese, and therefore I must make sure that I understand correctly.
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: the order of user and room variable

Postby Lapo » 04 Aug 2017, 13:21

Sure, no problem.
If there's anything else, let us know.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Stevenor and 64 guests