Extensions to create room variables

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

Moderators: Lapo, Bax

Post Reply
starvingeyes
Posts: 17
Joined: 25 Oct 2007, 05:50

Extensions to create room variables

Post by starvingeyes »

In a previous post I was trying to make a game room not be listed in the list of game rooms if the game was currently in play. I tried to do this by attaching a variable to the room called isInPlay, but was later informed that this would not work because it was not really possible and unwise to attach variables to rooms on the client side. I was told to use a server side extension to do this:

On the server side each User and Room object has carries a properties object where you can store any runtime values, status, flag etc... So you could use it for keeping the "inPlay" status of each room.

All you have to do is send a request from the client to your extension saying "join me in game room 10". The server side part will do all the necessary validation and either join the player or send back an error.

About real time updates of the status of each room ( game running, not running etc... ) you can send an additional update to your client that informs them about those status changes.
I generally understand the basics of loading an extension, but I don't know how in this instance to attach this variable to a game room from within the extension as file. Also what would I have to write in the swf file?

Do I load the extension here? or elsewhere? :

Code: Select all

function createRoom(name:String, pwd:String, max:Number) {
	hideWindow("newGameWindow");
	var gameRoom:Object = new Object();
	gameRoom.name = name;
	gameRoom.password = pwd;
	gameRoom.maxUsers = 8;
	gameRoom.isGame = true;
	gameRoom.isTemp = true;
	//
	//
	xt = {};
	xt.name = "isInPlay_";
	xt.script = "isInPlay_.as";
	gameRoom.extension = xt;
	//
	smartfox.createRoom(gameRoom);
}
But specifically how do I write the syntax in the .as extension file, to make this room variable show up when I go like this:

Code: Select all

smartfox.onRoomListUpdate = function(roomList:Object) {
	roomList_lb.removeAll();
	for (var i in roomList) {
		var room:Room = roomList[i];
		if (room.isGame()&room.isInPlay==false) {
			roomList_lb.addItem(room.getName()+" ("+room.getUserCount()+")", room.getId());
		}
	}
	roomList_lb.sortItemsBy("label", "ASC");
	// Join the default room
	this.joinRoom("The Entrance", "");
};
note the room.isInPlay==false in the above code

I have gone through the extension tutorials and examples and the solution to this problem isn't coming together in my mind with what I've gathered. Can you please help me out with this problem with specific syntax?

Jason
Post Reply