Getting / setting room variables is impossible
Posted: 25 Aug 2008, 19:47
Hi everyone !
I lost my day trying to do this thing and now I'm almost sure it's a smartfox bug...
I'm trying to duplicate a room when the previous one reach a certain limit. Of course, I create the new room dynamicaly this way :
And here's the return :
I tried it many ways, and it always does exactly the same thing : it parse the room vars, store it, I can trace the number of variables and the structure of the roomVars array, everything is fine, but wen I add it to the room, they're not taken into consideration...
It returns no error, the room is properly created, except I don't have the room vars.
It's certainly a bug, please can you tell me how to fix that asap ?
Thank you !
I lost my day trying to do this thing and now I'm almost sure it's a smartfox bug...
I'm trying to duplicate a room when the previous one reach a certain limit. Of course, I create the new room dynamicaly this way :
Code: Select all
// Get the previous room
var prevRoom = _server.getCurrentZone().getRoom(params.id);
// First, you have to create the room
// Exactly the same as the previously choosed.
var roomObj = {};
// Getting the display number
var dispName = getDisplayName(params.id);
roomObj.name = dispName;
roomObj.maxU = prevRoom.getMaxUsers();
roomObj.isGame = false;
roomObj.isLimbo = false;
roomObj.uCount = true;
roomObj.xtName = "room";
roomObj.xtClass = "mygame_sfs_room_extension.as";
// Room Vars : add the 2 vars
var roomVars = [];
var rVars = prevRoom.getVariables();
trace("-- ADD VARS TO ROOM -----");
for (var i = rVars.entrySet().iterator(); i.hasNext();)
{
var rVar = i.next();
trace("- Add var "+rVar.getKey()+" with value "+rVar.getValue().getValue());
roomVars.push({name:rVar.getKey(), val:rVar.getValue().getValue(), priv:true, persistent:false});
}
trace("-- END ADD VARS TO ROOM (add "+roomVars.length+" vars) -----");
trace("");
var newRoom = _server.createRoom(roomObj, user, true, true, roomVars)
// Then, join the room
if (newRoom == null)
trace("Impossible to create the room. You don't really need to handle this...");
else
_server.joinRoom(user, fromRoom, true, newRoom.getId());
trace("-- CHECK THE VARS FROM ROOM "+newRoom.getName()+" ----------------");
var rVars = newRoom.getVariables();
var cpt = 0;
for (var i = rVars.entrySet().iterator(); i.hasNext();)
{
var rVar = i.next();
trace("Variable "+rVar.getKey()+" : "+rVar.getValue().getValue());
cpt++;
}
trace("-- "+cpt+" vars returned ! ----------");Code: Select all
[mygame_sfs_zone_extension.as]: -- ADD VARS TO ROOM -----
[mygame_sfs_zone_extension.as]: - Add var RoomCfg with value xml/roomconfig_Garden.xml
[mygame_sfs_zone_extension.as]: - Add var SRoomId with value 2
[mygame_sfs_zone_extension.as]: -- END ADD VARS TO ROOM (add 2 vars) -----
[mygame_sfs_zone_extension.as]: 22:40:11.375 - [ INFO ] > Room Extension [ room ] created!
[mygame_sfs_room_extension.as]: mygame Room Extension v0.1.00 initialized [room:The Garden 1]
[mygame_sfs_zone_extension.as]: -- CHECK THE VARS FROM ROOM The Garden 1 ----------------
[mygame_sfs_zone_extension.as]: -- 0 vars returned ! ----------It returns no error, the room is properly created, except I don't have the room vars.
It's certainly a bug, please can you tell me how to fix that asap ?
Thank you !