Page 1 of 1
Room.getVariables() does not work!
Posted: 06 Aug 2008, 10:46
by itnix
Hello.
I've downloaded and installed SmartFoxServer PRO recently and was trying to explore.. All is good.. I connect.. login.. after that when I receive SFSEvent.onRoomListUpdate event and try to roundtrip evt.params.roomList (let's assume evt is the SFSEvent received by handler), there is an nothing there.. There is rooms but they don't seem to have any variables..
Btw my config file is as is default one.. I mean the room I've tried is TheoChat and the rooms got variables there by the config!
Thanks!

Posted: 06 Aug 2008, 12:45
by Lapo
You can only read variables in the room that you have joined.
You don't get the full list of variables for every room available, it usually takes too much bandwidth.
You can however force this behavior (receive all vars for all rooms) by setting the roomListVars attribute in the Zone config.
All the details are found in the docs, chapter 2.1
Posted: 06 Aug 2008, 12:45
by Lapo
btw, I have moved the topic as this is not a bug
Posted: 07 Aug 2008, 11:19
by itnix
Thanks a lot.. I'll try it..
Posted: 07 Aug 2008, 12:59
by itnix
Nope.. not working with roomListVars="true".
Here is the part of my config.xml :
Code: Select all
<Zone name="simpleChat" uCountUpdate="true" buddyList="20" maxUsers="4000" customLogin="false" roomListVars="true">
<Rooms>
<Room name="The Hall" maxUsers="50" isPrivate="false" isTemp="false" autoJoin="true" uCountUpdate="true" roomListVars="true">
<Vars>
<Var name="myVar" type="s" private="false">my test string</Var>
</Vars>
</Room>
<Room name="The Kitchen" maxUsers="50" isPrivate="false" isGame="false" isTemp="false" />
...
And the source of the test is here:
http://store3.data.bg/itni/sfstest2.rar
Posted: 07 Aug 2008, 13:31
by Lapo
Can't download anything.
Can you simply show the code you use to access the variables? (only the code of the onRoomListUpdate)
Posted: 07 Aug 2008, 13:44
by itnix
Code: Select all
private function onRoomListUpdateHandler(evt:SFSEvent):void {
var room:Room;
for (var r:String in evt.params.roomList) {
room = evt.params.roomList[r];
var vars:Array = room.getVariables();
log("Room "+room.getName()+" got "+vars.length+" vars");
}
//log(" Now joining room "+sfsRoom+"...");
SmartFox.addEventListener(SFSEvent.onJoinRoom, onRoomJoin);
SmartFox.addEventListener(SFSEvent.onJoinRoomError, onRoomJoinError);
SmartFox.joinRoom(sfsRoom);
}
Posted: 08 Aug 2008, 13:53
by Lapo
You don't get any length attribute in your code, because the Variables array does not have numeric keys.
Use this snippet to show the variables:
Code: Select all
function onRoomListUpdate(evt:SFSEvent):void
{
for each (var room:Room in evt.params.roomList)
{
trace("room: " + room.getName())
var vars:Array = room.getVariables()
for (var k:String in vars)
{
trace("\t" + k + " => " + vars[k])
}
}
}