Page 1 of 1

Empty RoomList error when returning to map from Game Room

Posted: 11 Dec 2008, 13:55
by mugambs
Hi,

I am trying to do some basic extensions to the examples supplied with the Openspace download.

Heres what I am trying to do. I am extending the Ranch example with a new exit, that takes the player into a quiz (flash based - nothing openspace). The user can cancel the quiz, or complete the quiz to return to the openspace map that they were in.

I have created a new sensor tile on the map

Ive also extended the timeline in the main flash app, and created a simple quiz screen, with a cancel button.

Ive added handlers to the actionscript (in the changeRoom() method) to take the user to the quiz, when they trigger the sensor tile.

Code: Select all

case "ranchQuiz":
	trace("User wants to start the quiz");
			
	inGame = true;
	currentMap = null;
			
	var gameRoom:Object = new Object()
	gameRoom.name = "ranchQuiz"
	gameRoom.maxUsers = 1
	gameRoom.isGame = true
	gameRoom.isTemp = true
	
	smartFox.createRoom(gameRoom)
	smartFox.joinRoom(gameRoom.name)
	gotoAndPlay("quiz");
	break
The quiz screen has a cancel button, with simple click handler. On click, it tries to return the user to Openspace map by doing something like

Code: Select all

inGame = false
	
nextMap = {}
nextMap.sfsRoomName = "Ranch (inside)"
nextMap.filename = "m1_RanchInside.xml"
nextMap.px = 6
nextMap.py = 10
nextMap.dir = 4

gotoAndStop("openspace")

//smartFox.getRoomList()
smartFox.joinRoom(nextMap.sfsRoomName)
Now, most of this code seems to work fine. Pressing the cancel button, returns the playhead to the first frame, and the map seems to load and display on screen correctly. But i get the following output

Code: Select all

Avatars' library loaded
Skins' library loaded
Backgrounds' library loaded
Map loaded & parsed: progress status should be displayed

****************************************************************
Internal error:
The room list is empty!
The client API cannot function properly until the room list is populated.
Please consult the documentation for more infos.
****************************************************************
TypeError: Error #1009: Cannot access a property or method of a null object reference.
	at com.smartfoxserver.openspace::OpenSpace/onMapRendered()
	at flash.events::EventDispatcher/dispatchEventFunction()
	at flash.events::EventDispatcher/dispatchEvent()
	at com.smartfoxserver.openspace.mvc::IsoEngineModel/onMapBuilt()
	at com.smartfoxserver.openspace.map::MapManager/onMapGenerationCompleted()
	at flash.events::EventDispatcher/dispatchEventFunction()
	at flash.events::EventDispatcher/dispatchEvent()
	at com.smartfoxserver.openspace.utils.executor::MultiFrameExecutor/runStep()
	at flash.utils::Timer/_timerDispatch()
	at flash.utils::Timer/tick()

Posted: 11 Dec 2008, 16:01
by Bax
When inside game rooms, some SmartFoxServer events are not received (check this page in the documentation). This can lead to problems.
Before leaving the the game room you have to request an updated roomlist to the server.

Posted: 11 Dec 2008, 22:16
by mugambs
Hi bax,

Thanks for the quick reply.

I have tried updating the code for exiting the game room based on your suggestion.

Code: Select all

trace("User wants to cancel the quiz");
	
nextMap = {}
nextMap.sfsRoomName = "Ranch (inside)"
nextMap.filename = "m1_RanchInside.xml"
nextMap.px = -1
nextMap.py = -1
nextMap.dir = -1
	
gotoAndStop("openspace")
	
smartFox.getRoomList()
inGame = false
smartFox.joinRoom(nextMap.sfsRoomName)
I still get the same error. (I added a flag test in the onSFSRoomListUpdate() method to skip the joinRoom code in there).

Is the strategy I am using to switch to and from game rooms correct? I notice in the Openspace API, you have methods for clear() and loadMap(). Should I be using those in conjunction with createRoom() and joinRoom()?

Posted: 12 Dec 2008, 08:26
by Bax
First of all if you use multiple frames in the Flash timeline, you should be aware that each time you move away from the frame containing OpenSpace, it is removed from the displaylist, but not from memory! So when you go back to that frame, a new instance of OpenSpace will be created, without destroying it. That means that each time you enter and exit a game, you are adding an OpenSpace instance in memory, with an incredible waste of memory and Flash Player resources. Before moving to the game frame you have to call the clear method. Also, it would be better to avoid using multiple frames. Or it would be better to instantiate OpenSpace via actionscript, creating it once and then reusing the same instance each time you exit the game.
One more thing: when you call smartFox.getRoomList() you have to wait for the onRoomListUpdate event before joining the new room.

Posted: 12 Dec 2008, 13:55
by mugambs
Do you have any examples of instantiating OpenSpace from Actionscript and joining / exiting a game room?

I have tried using the clear method when leaving Openspace, and then setting the nextMap info and calling getRoomList() to trigger the onRoomListUpdate and join the openspace room. I still get a RoomListEmpty error, but now, its thrown before the user joins the room, rather than after the map is rendered

Thanks

Posted: 12 Dec 2008, 17:12
by Bax
The problem here is that multiframe applications should be avoided when using ActionScript 3. We don't have the example you are looking for. We will take this suggestion for the future.
Why don't you open the game in the same frame where OpenSpace is contained? Simply "clear" OpenSpace and attach the movieclip containing your game above OS. When you close the game, remove the movieclip and tell OS to reload the previous map.

Posted: 14 Dec 2008, 14:42
by mugambs
Many thanks Bax,

That solution worked great!