ROOM_VARIABLES_UPDATE continuously updates (how to stop)?

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

Moderators: Lapo, Bax

madwilson79
Posts: 4
Joined: 21 Jan 2020, 13:10

ROOM_VARIABLES_UPDATE continuously updates (how to stop)?

Postby madwilson79 » 21 Jan 2020, 13:21

Code: Select all

sfs.addEventListener(SFS2X.SFSEvent.ROOM_VARIABLES_UPDATE, onRoomVariablesUpdate, this);

var room_vars = [];
room_vars.push(new SFS2X.SFSRoomVariable("retailer_player", your_user_ID) );
var isSent = sfs.send(new SFS2X.SetRoomVariablesRequest(room_vars) );


Using HTML5 JS

should this continuously update? Reason for asking is my browser becomes unresponsive defeating the purpose.

Does anyone have a good fix or example link to help drive me into the right direction to stop the continuously updating room variables?

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

Re: ROOM_VARIABLES_UPDATE continuously updates (how to stop)?

Postby Lapo » 21 Jan 2020, 15:44

Hi,
it depends on what you mean by continuously. There's a limit of requests per second you can send to the server and connected clients. If you push it too hard you may overwhelm the client with packets to receive.

What update rate are you using?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
madwilson79
Posts: 4
Joined: 21 Jan 2020, 13:10

Re: ROOM_VARIABLES_UPDATE continuously updates (how to stop)?

Postby madwilson79 » 21 Jan 2020, 16:58

Code: Select all

// index
$("body").on('click','#pick_factory', function() {
  $("#select_player_type_window").hide("slow");
  picked_game_type = "factory";
  onRoomVariablesUpdate(event);
});

// main.js
sfs.addEventListener(SFS2X.SFSEvent.ROOM_VARIABLES_UPDATE, onRoomVariablesUpdate, this);

function onRoomVariablesUpdate(event)
{
   if(picked_game_type != null)
   {
      if(picked_game_type == "factory")
      {
         var room_vars = new SFS2X.SFSRoomVariable("factory_player", your_user_ID);
         sfs.send(new SFS2X.SetRoomVariablesRequest([room_vars]) );
      }
   }
}

// chrome console log


sfs2x-api-1.7.11.js:6 [ SFS2X | INFO ] Sending request 'SetRoomVariables' to server
sfs2x-api-1.7.11.js:6 [ SFS2X | INFO ] Handling server event: SetRoomVariables (11)
sfs2x-api-1.7.11.js:6 [ SFS2X | INFO ] Sending request 'SetRoomVariables' to server
sfs2x-api-1.7.11.js:6 [ SFS2X | INFO ] Handling server event: SetRoomVariables (11)
sfs2x-api-1.7.11.js:6 [ SFS2X | INFO ] Sending request 'SetRoomVariables' to server
sfs2x-api-1.7.11.js:6 [ SFS2X | INFO ] Handling server event: SetRoomVariables (11)
sfs2x-api-1.7.11.js:6 [ SFS2X | INFO ] Sending request 'SetRoomVariables' to server
sfs2x-api-1.7.11.js:6 [ SFS2X | INFO ] Handling server event: SetRoomVariables (11)
// act... KEEPS GOING UNTIL browser is unresponsive.


the room variable gets updated

I bassed this code off the "AdvancedChat"

why would the request keep being requested?

What I am attempting to do is :
Join Lobby -- Works
User-Created New Room + room Variables -- Works
user(s) joined new room -- Works
users are asked to pick one of 4 player types and Update Room Variables -- Works BUT keeps requesting update variables.

Am I missing a step to stop the request?

Where in the admin tool is the "What update rate are you using?"
madwilson79
Posts: 4
Joined: 21 Jan 2020, 13:10

Re: ROOM_VARIABLES_UPDATE continuously updates (how to stop)?

Postby madwilson79 » 21 Jan 2020, 17:38

FIX:

don't call the function onRoomVariablesUpdate(event) move all the room variables update to a function that isn't attached to

sfs.addEventListener(SFS2X.SFSEvent.ROOM_VARIABLES_UPDATE, onRoomVariablesUpdate, this);
User avatar
Rob
Posts: 53
Joined: 01 Jul 2017, 07:33

Re: ROOM_VARIABLES_UPDATE continuously updates (how to stop)?

Postby Rob » 22 Jan 2020, 01:36

Your problem is that you set a new room variable in the ROOM_VARIABLES_UPDATE callback, which is triggered every time a room variable changes. So it will generate an infinite loop.

Don't set any room variables in the callback. Set them on the server side, or move them to some other part of the client-side code.
madwilson79
Posts: 4
Joined: 21 Jan 2020, 13:10

Re: ROOM_VARIABLES_UPDATE continuously updates (how to stop)?

Postby madwilson79 » 22 Jan 2020, 22:28

thanks

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Stevenor and 86 guests