Room.getVariables() does not work!

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

Post Reply
itnix
Posts: 24
Joined: 06 Aug 2008, 10:36
Location: /root

Room.getVariables() does not work!

Post 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! :roll:

Thanks! :)
Image
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post 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
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

btw, I have moved the topic as this is not a bug
Lapo
--
gotoAndPlay()
...addicted to flash games
itnix
Posts: 24
Joined: 06 Aug 2008, 10:36
Location: /root

Post by itnix »

Thanks a lot.. I'll try it..
Image
itnix
Posts: 24
Joined: 06 Aug 2008, 10:36
Location: /root

Post 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
Image
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Can't download anything.
Can you simply show the code you use to access the variables? (only the code of the onRoomListUpdate)
Lapo
--
gotoAndPlay()
...addicted to flash games
itnix
Posts: 24
Joined: 06 Aug 2008, 10:36
Location: /root

Post 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);
		}
Image
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post 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])
		}
	}
}
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply