ROOM_ADDED is not fired

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Post Reply
haplo
Posts: 78
Joined: 08 Jun 2010, 13:32

ROOM_ADDED is not fired

Post 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
haplo
Posts: 78
Joined: 08 Jun 2010, 13:32

Post 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.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post 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.
Lapo
--
gotoAndPlay()
...addicted to flash games
haplo
Posts: 78
Joined: 08 Jun 2010, 13:32

Post 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]
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post 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
Lapo
--
gotoAndPlay()
...addicted to flash games
sHTiF
Posts: 102
Joined: 30 Sep 2010, 20:14

Post 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?
Pushing the limits of flash platform at http://blog.flash-core.com
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Yes, that would be a possible exception to using the API
Lapo
--
gotoAndPlay()
...addicted to flash games
haplo
Posts: 78
Joined: 08 Jun 2010, 13:32

Post 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

Code: Select all

null
Post Reply