Are all updated variables can be collected by client in one event triggering?

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

Moderators: Lapo, Bax

birdinforest
Posts: 2
Joined: 17 Aug 2017, 15:06

Are all updated variables can be collected by client in one event triggering?

Postby birdinforest » 19 Aug 2017, 20:44

I get a issue that when multiple variables have been updated on server side, client has a chance to missing one variable updated.

On server side, two variables are modified and set in the same time:

Code: Select all

List<RoomVariable> vars = Arrays.asList
                (
                        new SFSRoomVariable("turn", 0),
                        new SFSRoomVariable("discard", 0),
                );

The client tries to collect variable "discard" when the variable "turn" has been updated:

Code: Select all

   void OnRoomVar (BaseEvent evt)
   {
      int turnUserID = theRoom.GetVariable("turn").GetIntValue();
      if(turnUserID != latestUserID)
      {
         ISFSObject objIn = new SFSObject();
                  objIn = theRoom.GetVariable("discard").GetSFSObjectValue();
                  if (objIn != null && !objIn.IsNull("discard"))
                  {                         
                      ByteArray ba = objIn.GetByteArray("discard");
                      byte[] cc = ba.ReadBytes(ba.Length);
                      int dicardsLength = cc.Length;
                      if (dicardsLength > 0)
                      {
                         //...
                      }   
                  }
      }

It works in most of times but has a chance that when 'turn' has been updated the client can't get modified 'discards' variable.

Thanks.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Are all updated variables can be collected by client in one event triggering?

Postby Lapo » 20 Aug 2017, 08:00

The IsNull() method does not check if there is no variable. It checks that a variable exists of type null.
In other words in an SFSObject you can have a key that correspond to an object with no value.

This is not the same as checking that the object != null (i.e. null pointer)

If you want to check the existence of an item in the SFSObject use the containsKey(...) method instead.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Thomasea and 76 guests