room variables is null~

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Post Reply
king3200
Posts: 25
Joined: 28 Oct 2010, 01:48

room variables is null~

Post by king3200 »

hello~~
I created 100 rooms into 8 groups when Zone extension has been initalized~~~and every room has 2 variables~~~I create them like this:

Code: Select all

List<RoomVariable> variables = new ArrayList<RoomVariable>();
		variables.add(new SFSRoomVariable("btnPoint", serverType.getRoomButtomPoint()));
		variables.add(new SFSRoomVariable("state", GameState.WAITTING_TO_START.toString()));

		newRoomSets.setRoomVariables(variables);
but when client join a room~~I can't get any variable.
Client will automatically update room variables?
thank you~~
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: room variables is null~

Post by rjgtav »

Hi.
Has the client joined those rooms whose variables you're trying to access?
Remember that for receiving variables from a room by just joining its Room Group, you have to set those variables as global.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
king3200
Posts: 25
Joined: 28 Oct 2010, 01:48

Re: room variables is null~

Post by king3200 »

rjgtav wrote:Hi.
Has the client joined those rooms whose variables you're trying to access?
Remember that for receiving variables from a room by just joining its Room Group, you have to set those variables as global.
thank you ~~~ I change my cods like this

Code: Select all

List<RoomVariable> variables = new ArrayList<RoomVariable>();
variables.add(new SFSRoomVariable("btnPoint", point, false, false, true));
variables.add(new SFSRoomVariable("state", GameState.WAITTING_TO_START.toString(), false, false, true));
newRoomSets.setRoomVariables(variables);
but I found my test client can not receive any room variable update...I have registed SFSEvent.ROOM_VARIABLES_UPDATE and joined a room belong 'default' group...
in zone settings~~~Public Room Groups and Default Room Groups are 'default'~~~
king3200
Posts: 25
Joined: 28 Oct 2010, 01:48

Re: room variables is null~

Post by king3200 »

I checked client debug trace just now, and I found room variables message came back by JoinRoom event~~~but I can't use room.getvariables() to get any variable yet...
here is the trace log:

Code: Select all

[SFS - INFO] JoinRoom { Message id: 4 }
{ Dump: }

	(sfs_array) r: 
		(int) 153
		(utf_string) room:152
		(utf_string) default4
		(bool) true
		(bool) false
		(bool) false
		(short) 1
		(short) 3
		(sfs_array) 
			(sfs_array) 
				(utf_string) roomBottomPoint
				(byte) 2
				(int) 1000
				(bool) false
				(bool) false
			
			(sfs_array) 
				(utf_string) roomGameState
				(byte) 4
				(utf_string) WAITTING_TO_START
				(bool) false
				(bool) false
			
		
		(short) 0
		(short) 0
	
	(sfs_array) ul: 
		(sfs_array) 
			(int) 4
			(utf_string) 2282
			(short) 0
			(short) 1
			(sfs_array) 
				(sfs_array) 
					(utf_string) playerUserName
					(byte) 4
					(utf_string) 
				
				(sfs_array) 
					(utf_string) playerCanRobDizhu
					(byte) 1
					(bool) false
				
				(sfs_array) 
					(utf_string) playerRobTime
					(byte) 2
					(int) 0
				
				(sfs_array) 
					(utf_string) nick
					(byte) 4
					(utf_string) 
				
				(sfs_array) 
					(utf_string) playerCurState
					(byte) 4
					(utf_string) 
				
				(sfs_array) 
					(utf_string) playerRole
					(byte) 2
					(int) 1
				
				(sfs_array) 
					(utf_string) playerIsReady
					(byte) 1
					(bool) false
				
				(sfs_array) 
					(utf_string) playerTitle
					(byte) 4
					(utf_string) 
				
				(sfs_array) 
					(utf_string) playerMac
					(byte) 4
					(utf_string) test199
				
				(sfs_array) 
					(utf_string) playerCurPoint
					(byte) 3
					(double) 5000
				
				(sfs_array) 
					(utf_string) playerVip
					(byte) 2
					(int) 0
				
			
		
	

join Room:[Room: room:152, Id: 153, GroupId: default4]
-----------[Room: room:152, Id: 153, GroupId: default4]
room variables count : 0
[SFS - INFO] UserExitRoom { Message id: 1004 }
{ Dump: }

	(int) r: 0
	(int) u: 4

[SFS - INFO] Data Read: Binary Size: 122
80 00 77 12 00 03 00 01 61 03 00 0C 00 01 63 02 	..w.....a.....c.
00 00 01 70 12 00 02 00 01 75 04 00 00 00 04 00 	...p.....u......
02 76 6C 11 00 03 11 00 03 08 00 11 70 6C 61 79 	.vl.........play
65 72 43 61 6E 52 6F 62 44 69 7A 68 75 02 01 01 	erCanRobDizhu...
01 11 00 03 08 00 0D 70 6C 61 79 65 72 52 6F 62 	.......playerRob
54 69 6D 65 02 02 04 00 00 00 00 11 00 03 08 00 	Time............
0E 70 6C 61 79 65 72 43 75 72 50 6F 69 6E 74 02 	.playerCurPoint.
03 07 40 B3 88 00 00 00 00 00                   	..@.......      

[SFS - INFO] SetUserVariables { Message id: 12 }
{ Dump: }

	(sfs_array) vl: 
		(sfs_array) 
			(utf_string) playerCanRobDizhu
			(byte) 1
			(bool) true
		
		(sfs_array) 
			(utf_string) playerRobTime
			(byte) 2
			(int) 0
		
		(sfs_array) 
			(utf_string) playerCurPoint
			(byte) 3
			(double) 5000
		
	
	(int) u: 4

User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: room variables is null~

Post by rjgtav »

Yes the variables were received correctly on the client, so you should be able to retrieve them.
What code are you using for retrieving that variable? And when are you doing it? On the joinRoom event?
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
king3200
Posts: 25
Joined: 28 Oct 2010, 01:48

Re: room variables is null~

Post by king3200 »

yes, I did it in joinRoom event~~~here is all my test client code~~~

Code: Select all

public class Main extends Sprite 
	{
		var sfs:SmartFox;
		var myUser:User;
		var currentRoom:Room;
		
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			
			sfs = new SmartFox();
			sfs.useBlueBox = false;
			sfs.addEventListener(SFSEvent.CONNECTION, sfs_connection);
			sfs.addEventListener(SFSEvent.CONNECTION_LOST, sfs_connectionLost);
			sfs.addEventListener(SFSEvent.LOGIN, sfs_login);
			sfs.addEventListener(SFSEvent.ROOM_JOIN, sfs_roomJoin);
			sfs.addEventListener(SFSEvent.ROOM_VARIABLES_UPDATE, sfs_roomVariablesUpdate);
			
			sfs.connect(ip, port);
		}
		
		private function sfs_roomVariablesUpdate(e:SFSEvent):void 
		{
			trace("room variables update!!!!!!!!!!!!!!!!!!!!!!!");
		}
		
		private function sfs_roomJoin(e:SFSEvent):void 
		{
			trace("you joined room:" + e.params.room);
			this.currentRoom = e.params.room;
			if (currentRoom.name == "lobby")
			{
				var roomlist:Array = sfs.getRoomListFromGroup("default1");
				var roomToJoin:Room = roomlist[0] as Room;
				
				sfs.send(new JoinRoomRequest(roomToJoin.id, "", this.currentRoom.id, false));
			}
			else
			{
				
				trace(currentRoom+"  variables:" + currentRoom.getVariables.length);
			}
		}
		
		private function sfs_login(e:SFSEvent):void 
		{
			trace("login OK");
			
		}
		
		private function sfs_connectionLost(e:SFSEvent):void 
		{
			trace("you have lost connection");
		}
		
		private function sfs_connection(e:SFSEvent):void 
		{
			sfs.send(new LoginRequest("test", "", "normal", null));
		}
		
	}
and result trace

Code: Select all

login OK
you joined room:[Room: lobby, Id: 0, GroupId: lobby]
you joined room:[Room: room:38, Id: 39, GroupId: default1]
[Room: room:38, Id: 39, GroupId: default1]  variables:0
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: room variables is null~

Post by rjgtav »

It looks like you have a small typo in your docs. getVariables is a method, not a property.
That said, you retrieve the variables list by doing:

var variables:Array = room.getVariables();
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Post Reply