Server side (in a room extension handler):
Code: Select all
UserVariable na = new SFSUserVariable("na", "My Character Name");
getApi().setUserVariables(user, Arrays.asList(na));
try {
Room room = getParentExtension().getParentZone().getRoomByName(room_name);
if (room == null) {
throw new SFSException("Room ("+room_name+") is unavailable/not created");
}
getApi().joinRoom(user, room);
SFSMMOApi mmoApi = (SFSMMOApi)SmartFoxServer.getInstance().getAPIManager().getMMOApi();
mmoApi.setUserPosition(user, new Vec3D(0.0f, 0.0f, 0.0f), room);
} catch (SFSException e) {
trace("CharacterManagerEventHandler.EnterWorld exception: "+e.getMessage());
}
Client side: (Note: this_user is set as a class variable in the handler and outputs the user info without any problem.)
Code: Select all
void OnRoomJoin(BaseEvent e){
Debug.Log ("Successfully joined room: "+e.Params["room"]+ " as: " +this_user);
sfs.RemoveAllEventListeners();
List<User> users = sfs.UserManager.GetUserList();
foreach (User user in users){
Debug.Log (user);
List<UserVariable> vars = user.GetVariables();
foreach (UserVariable var in vars){
Debug.Log(var.Name + ":"+var.Type);
}
}
Debug.Log(this_user.GetVariable("na").GetStringValue());
}
Code: Select all
Successfully joined room: [Room: Playground, Id: 1, GroupId: default] as: [User: testuser, Id: 3, isMe: True]
UnityEngine.Debug:Log(Object)
[User: testuser, Id: 3, isMe: True]
UnityEngine.Debug:Log(Object)
NullReferenceException: Object reference not set to an instance of an object
CharacterManager.OnRoomJoin (Sfs2X.Core.BaseEvent e)
This seems to follow the pattern in the docs unless I'm missing something. Any ideas where I've gone astray? Could the room join be happening before the vars are set on the server (and thus creating an async issue)?
Any help is appreciated at this point.