User variable and room variable
User variable and room variable
in my game, all user variables and room variables are created on server side, here is my question: if I update a user variable or room variable on server side, will all users in this room trigger update event automatically or I need to send some thing to all of user in this room?
-
- Posts: 41
- Joined: 06 Jul 2017, 04:35
Re: User variable and room variable
what function are you using to update your user/room variable ?
if you used the function in the api (this code works inside an extension for example)
the last 2 booleans in the function are fireClientEvent,fireServerEvent
this will fire the events to update the client and so
and this is the documentations for the method
the same thing goes for setRoomVariables method
if you used the function in the api (this code works inside an extension for example)
Code: Select all
getApi().setUserVariables(user,vars,true,true);
the last 2 booleans in the function are fireClientEvent,fireServerEvent
this will fire the events to update the client and so
and this is the documentations for the method
void setUserVariables(User owner,
java.util.List<UserVariable> variables,
boolean fireClientEvent,
boolean fireServerEvent)
Set User Variables. Only variables that change are broadcast to the Users that can "see" the sender. In order to delete a variable you can set it to null.
Parameters:
owner - the User for which variables are set
variables - a list of UserVariables
fireClientEvent - fires client side Event
fireServerEvent - fires server side Event
the same thing goes for setRoomVariables method
Re: User variable and room variable
Wei wrote:in my game, all user variables and room variables are created on server side, here is my question: if I update a user variable or room variable on server side, will all users in this room trigger update event automatically or I need to send some thing to all of user in this room?
Yes, updating a Room variable will trigger and update for everyone regardless of which side it was set (client or server)
As Hassan pointed out in his reply, make sure to use
Code: Select all
getApi().setUserVariables(...)
on the server side.
cheers
Re: User variable and room variable
Got it and thanks.
But I have another one, how could I update room variable and user variable。
I've set up room variables and user variable when User
And how can I update them? I've searched documents, it looks like no method for doing that. Or I just need to do new SFSRoomVariable() again?
But I have another one, how could I update room variable and user variable。
I've set up room variables and user variable when User
Code: Select all
UserVariable score = new SFSUserVariable("score", 1);
List<UserVariable> userVars = new ArrayList<>();
userVars.add(score);
getApi().setUserVariables(theUser, userVars);
RoomVariable round = new SFSRoomVariable("round", 1);
round.setPrivate(true);
round.setGlobal(true);
RoomVariable remain = new SFSRoomVariable("remain", 30);
remain.setGlobal(true);
remain.setPrivate(true);
List<RoomVariable> roomVars = Arrays.asList(round, remain);
Room room = getParentExtension().getParentZone().getRoomByName(roomName);
getApi().setRoomVariables(theUser, room, roomVars);
And how can I update them? I've searched documents, it looks like no method for doing that. Or I just need to do new SFSRoomVariable() again?
Code: Select all
List<Room> Rooms = user.getJoinedRooms();
Room currentRoom = Rooms.get(0);
RoomVariable roomVar = currentRoom.getVariable("round");
Re: User variable and room variable
Wei wrote:Got it and thanks.
And how can I update them? I've searched documents, it looks like no method for doing that. Or I just need to do new SFSRoomVariable() again?
Yes, you just set it again. Using a new object.
cheers
Re: User variable and room variable
sure, tanks
Re: User variable and room variable
here comes another one, when a user join a game room, the game room has some room variables, how could I get all those room variables when I join the room, or it'll trigger room_variable_change event directly when I join the room?
Re: User variable and room variable
RoomVariables are sent out to the client in the ROOM_JOIN event.
In that event you are passed a Room object and you can call getVariables() on it to get all vars in the Room.
cheers
In that event you are passed a Room object and you can call getVariables() on it to get all vars in the Room.
cheers
Who is online
Users browsing this forum: No registered users and 87 guests