Learning to use RoomVariables

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
foxter888
Posts: 78
Joined: 10 Apr 2011, 05:52
Location: united states

Learning to use RoomVariables

Post by foxter888 »

hi could anyone direct me about how to change values of a room variable from the server?
i have tried using the RoomVariable class and the SFSRoomvariable and still somewhat confuse like how i it knows what type of object i'm using where it will be a string, int etc and so on.

i already know how to make it so in unity i'm able to get the room variables like reading what their values are, now in this case i only want to set the values by the server. i tried something like SetRoomVariable(RoomVariable, bool); i don't know what 's the bool for lol.

in here i have a half way code about setting a room vairbale which i called game started, in here i made a countdown timer and once it's finish set the room variable to true, i have other variables such as the name of the level and so on so forth, i know there could be other aproaches but
still this seemes a better aproach of doing it.

here's the snipet which i'm still trying to work on so far:

Code: Select all

 
        String Name = data.getUtfString("name");
        users = this.getParentExtension().getParentRoom().getUserList();
        room = this.getParentExtension().getParentRoom();
        
        try
        {
            SmartFoxServer sfs = SmartFoxServer.getInstance();
            
            RoomVariable rv;
            rv = room.getVariable("gameStarted");
            
            
            if(started)
            {
              if(rv.getBoolValue() == false)
              {
                  room.setVariable(rv);
              }
            }
get to work you slacker!!!
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: Learning to use RoomVariables

Post by rjgtav »

Hi.
Just to make sure, you're using SFS2x, correct? In that case, then i'll have to move this topic to the appropriate section.
Anyway, you can't use those methods (room.setRoomVariable(), zone.addRoom(), etc) directly. Please use the SFSApi class for everything you need to do which implies updating the clients and or rooms/zones, etc. The problem is that these methods are used internally by the server, and in that case, for example, that method only updates the variable locally, it doesn't inform the clients about it.

So, never forget to use the SFSApi in everything you need.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
foxter888
Posts: 78
Joined: 10 Apr 2011, 05:52
Location: united states

Re: Learning to use RoomVariables

Post by foxter888 »

i see what you are saying. i found the answer and made it work. by doing room.SetVariable()
in the unity client it doesn't seems to update right away until i click on join room then all the sudden the gui shows the correct updated variable and such.
but then again this part that i mention could be something in need to correct on the client side lol.
get to work you slacker!!!
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Re: Learning to use RoomVariables

Post by rjgtav »

So you're using SFS1x, correct? Please specify the version of the server you're using, otherwise it is more difficult to help.
Anyway, in the last post, i told you the solution in case you were using SFS2x. In SFS1x, instead of the SFSApi class, you have to use the ExtensionHelper class, and use the setRoomVariables(room, user, vars, setOwnership, broadcastAll). If you use that method and set the broadcastAll parameter to true, then you'll get the ROOM_VARIABLES_UPDATE event on the client-side, and don't need to rejoin the room in order to see the updated value.
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Post Reply