Page 1 of 1
[SOLVED] Question about Reserved room variables !!!
Posted: 08 Mar 2012, 11:02
by secret007
Hi,
I have created SFSGameSettings object and set "notifyGameStarted" to true and when i m listening to this variable in OnRoomVariablesUpdate function like this :
Code: Select all
var changedVars:Array = e.params.changedVars as Array;
if(changedVars.indexOf(ReservedRoomVariables.RV_GAME_STARTED) != -1)
{
trace("game is started");
}
so, when the limit reaches to 2 players its showing game started but when any of the player leaves the room or disconnected its also tracing game started why is that ? because now the room contains only one player so it should not have to come in this condition ...
Re: Question about Reserved room variables !!!
Posted: 10 Mar 2012, 10:42
by Lapo
Because the variable changes state and you don't check it.
Your code just checks if the variable was changed but not HOW it changed, do you follow?
When the two players are in the room, the variable will be set to true, when a user is lost the game must stop and the RoomVar value is changed to false.
Re: Question about Reserved room variables !!!
Posted: 12 Mar 2012, 09:54
by secret007
ok you are right but can you help more to sort out this thing, currently i m checking like this ,
Code: Select all
if(changedVars.indexOf(ReservedRoomVariables.RV_GAME_STARTED) != -1)
{
if(ReservedRoomVariables.RV_GAME_STARTED == "true")
trace("game started");
else
trace("game stopped");
}
in this case, its always tracing "game stopped", however if i changes the second if condition with this one,
Code: Select all
if(ReservedRoomVariables.RV_GAME_STARTED)
so its now always tracing "game started",
can you elaborate with code whats the exact matching scenario ???
Re: Question about Reserved room variables !!!
Posted: 12 Mar 2012, 10:05
by Lapo
Code: Select all
if(ReservedRoomVariables.RV_GAME_STARTED)
I bet you always get the same value, this is a constant

You must check the variables passed by the ROOM_VARIABLES_UPDATE event, ok?
Please do check the documentation for that event, also we provide a working example that uses this feature. The example is called "The Game Lobby"
Re: Question about Reserved room variables !!!
Posted: 13 Mar 2012, 10:53
by secret007
yes i m getting changed vars array on RoomVarUpdate handler but i cant figure out how to check the value of this Constant since its a constant how its value will be changed ? i just want to get true if 2 users are in the room and false if one of them left so that i can update dynamic rooms list to clients.
yh will be very useful if you provide some working example in the documentation ...
THANKS.
Re: Question about Reserved room variables !!!
Posted: 13 Mar 2012, 15:11
by Bax
You are using the wrong code to retrieve the variable value!
Please check the SFSEvent.ROOM_VARIABLES_UPDATE API documentation: the provided example shows the right way to go.
Re: Question about Reserved room variables !!!
Posted: 14 Mar 2012, 08:37
by secret007
Bax wrote:You are using the wrong code to retrieve the variable value!
Please check the SFSEvent.ROOM_VARIABLES_UPDATE API documentation: the provided example shows the right way to go.
yes you'r right, basically its a constant but its value will be treated like a boolean, here is the right way to go,
Code: Select all
room.getVariable(ReservedRoomVariables.RV_GAME_STARTED).getBoolValue()
Problem solved
