_server.getCurrentRoom() - null for extension in config

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

Moderators: Lapo, Bax

Posts: 72
Joined: 11 Aug 2010, 19:48

_server.getCurrentRoom() - null for extension in config

Postby Rashomon » 28 Sep 2011, 19:24

(Using Actionscript 3 on client, and Actionscript 1 on server)

I'm trying to use the _server object in my extensions to get info about my room. For example:

Code: Select all

var currentRoom = _server.getCurrentRoom();
trace("Room: " + currentRoom);
trace("Room name: " + currentRoom.getName());
trace("Users in room: " + currentRoom.getUserCount());

This works fine in myGameRoomExtension, but not in myDatabaseExtension. I get the following error in my log:

[myDatabaseExtension.as]: room: null
16:24:38.969 - [ WARNING ] > Error in extension [ myDatabaseExtension.as ]: TypeError: Cannot call method "getName" of null (myDatabaseExtension.as#2085) Internal:
510 -- Line number: 509 in file: myDatabaseExtension.as

Why is currentRoom null?

The only thing I can see that I'm doing different is that I'm creating myGameRoomExtension in AS3, but I'm creating the myDatabaseExtension in the config.xml file.

myGameRoomExtension (client):

Code: Select all

var newGameRoom:Object = new Object();
newGameRoom.name = "game" + smartFox.myUserId;
newGameRoom.maxUsers = 3
newGameRoom.maxSpectators = 0
newGameRoom.isGame = true
newGameRoom.isTemp = true
var xt:Object = {}
xt.name = "race"
xt.script = "myGameRoomExtension.as"
newGameRoom.extension = xt
smartFox.createRoom( newGameRoom )

myDatabaseExtension (in config.xml):

Code: Select all

   <extension name="myDatabaseExtension"  className="myDatabaseExtension.as" type="script" />
Posts: 72
Joined: 11 Aug 2010, 19:48

Postby Rashomon » 29 Sep 2011, 13:10

Ok. This is what finally worked for me:

Code: Select all

function handleRequest(cmd, params, user, fromRoom)
     if (cmd == "checkForAvatar")
          var zone = _server.getCurrentZone();
          var currentRoom = zone.getRoom(fromRoom);
          // or _server.getCurrentZone().getRoom(fromRoom);
          var uList = currentRoom.getAllUsers();
          _server.sendResponse(response, -1, null, uList);

I'm not sure why I could use _server.getCurrentRoom() for one extension, but I had to use zone.getRoom() for the other extension. Does anyone know?
User avatar
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Postby BigFIsh » 30 Sep 2011, 17:04

_server.getCurrentRoom() only works for room extensions. So if myDatabaseExtension is a zone extension, that method won't work.
Smartfox's forum is my daily newspaper.

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: Bing [Bot] and 42 guests