Page 1 of 1
ROOM_ADDED is not fired
Posted: 15 Nov 2010, 02:43
by haplo
on a zone level extenstion i have
Code: Select all
@Override
public void init()
{
trace("room init");
addEventHandler(SFSEventType.ROOM_ADDED , RoomAddedHandler.class);
}
and then
Code: Select all
public class RoomAddedHandler extends BaseServerEventHandler {
@Override
public void handleServerEvent(ISFSEvent event) throws SFSException
{
MainZone gameExt = (MainZone) getParentExtension();
gameExt.trace("ssss");
}
}
The room are predfine and AdminTool and not generated from users.
is this event only fired when user creating rooms? if so when can i make sure a pre defined room is fully instantiated
Posted: 16 Nov 2010, 00:55
by haplo
hi guys im a little bit stuck on my project becuz of this . I predfined room using admintool and i can't seems to tell when they are fully instantiated.
Posted: 16 Nov 2010, 08:04
by Lapo
Yes, the event is fired when a new dynamic room is created. The rooms defined in the config are created before your extension even starts.
Since those Rooms are static you will find them already created by the time the init() method is executed in your extension.
Posted: 16 Nov 2010, 09:34
by haplo
so im trying to set a new variable on static room but i get
Code: Select all
java.lang.nullpointerexception
//the stack trace starst with
com.smartfoxserver.bitswarm.io.response.write(response.java:74);
Code: Select all
public class Main extends SFSExtension {
private GameBoardgameBoard;
@Override
public void init()
{
gameBoard = new GameBoard(this);
}
}
Code: Select all
public final class GameBoard {
public GameBoard (Main main)
{
getApi().setRoomVariables(null, this.main.getParentRoom(), roomVariables);
}
[code]
Posted: 16 Nov 2010, 10:27
by Lapo
The version of the method you are using attempts to send an update to the clients but at init() time the server is not even fully started up.
Use the full version of the method:
setRoomVariables(User user, Room targetRoom, List<RoomVariable> variables, boolean fireClientEvent, boolean fireServerEvent, boolean overrideOwnership)
and set the fireClientEvent and fireServerEvent to false
Posted: 16 Nov 2010, 11:08
by sHTiF
Lapo isn't it better in this scenario to do it through Room interface method setVariable instead? Isn't it exactly the same as setting it through api but without the events send?
Posted: 16 Nov 2010, 12:59
by Lapo
Yes, that would be a possible exception to using the API
Posted: 17 Nov 2010, 00:23
by haplo
i must be doing something wrong
Code: Select all
public class Main extends SFSExtension {
private GameBoardgameBoard;
@Override
public void init()
{
gameBoard = new GameBoard(this);
}
}
Code: Select all
public final class GameBoard {
public GameBoard (Main main)
{
roomStyle = new SFSRoomVariable("roomStyle","test" );
roomVariables.add(roomStyle);
this.main.getApi().setRoomVariables(null, this.main.getParentRoom(), roomVariables,false,false,true);
}
and on the client side
Code: Select all
var rv:RoomVariable = serverInterface.sfs.lastJoinedRoom.getVariable("roomStyle");
trace(rv);
but out put