Room Object doesn't work ... No Clue What's Wrong

You think you've found a bug? Please report it here.

Moderators: Lapo, Bax

Post Reply
XceeD
Posts: 15
Joined: 20 Oct 2006, 00:30

Room Object doesn't work ... No Clue What's Wrong

Post by XceeD »

Code: Select all

smartfox.onJoinRoom = function(roomObj:Room)
{
	tempUserList = smartfox.getRoom(smartfox.activeRoomId).getUserList();
	trace(roomObj)
	trace(tempUserList )

}
Here's the code... It traces "undefined" both times... When I dug deeper into the reason, I found out that the Room object itself isn't working... I removed and installed the API over and over again but it still doesn't work.

Sorry if this was already asked but I tried to search and couldn't find anything on it.

-XceeD
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

I don't understand your code.
If you've just joined a room, the roomObj represents the that room.

Why don't you use this code instead?

Code: Select all

tempUserList = roomObj.getUserList()
Lapo
--
gotoAndPlay()
...addicted to flash games
XceeD
Posts: 15
Joined: 20 Oct 2006, 00:30

Post by XceeD »

Well, let me explain it a bit more...
The thing is, roomObj is undefined and when I do roomObj.getUserList() it's still undefined! I don't understand what's wrong!


trace(roomObj.getUserList()) becomes undefined.

edit:
I don't if this has anything to do with this...

Code: Select all

	if (evt.name == "userLost")
	{
		var uid = evt.userId
		var roomIds = evt.roomIds
		var gameRooms = _server.getCurrentZone().getRooms()
		
		var rId = roomIds[0]
		var gameRoom = gameRooms[rId]
		trace(gameRoom + " " + gameRooms + " " + rId)
		var lostUser = gameRoom.getAllUsers()[uid]

		delete gameRoom.userList[uid]
		delete userList[nick]
	}
The trace comes out with:
[tobattles.as]: undefined [Ljava.lang.Object;@120d62b 2
18:27:51.515 - [ WARNING ] > Error in extension [ tobattles.as ]: TypeError: Cannot call method "getAllUsers" of undefined (tobattles.as#1191) Line: 202

What confused me was "[Ljava.lang.Object;@120d62b". I keep seeing that when I'm using the server to trace rooms or using the server to send a user list to the client.

I don't understand what's wrong because I used to use SFS in the summer. I try again now and it's not working...
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Well, let me explain it a bit more...
The thing is, roomObj is undefined and when I do roomObj.getUserList() it's still undefined!
ah! ok... then it's obvious. You can't read any property or call any method on an undefined object, because ... it doesn't exist :)

If the roomObj is undefined you've probably skipped the onRoomListUpdate event, and you've tried joining a room before populating the client side list of rooms.
Lapo
--
gotoAndPlay()
...addicted to flash games
XceeD
Posts: 15
Joined: 20 Oct 2006, 00:30

Post by XceeD »

Thank you so much! It worked perfectly!
For some reason, whenever I login, it doesn't evoke the onRoomListUpdate event. I manually made it go and after the login and it worked!

Thank you so much!
Post Reply