[SOLVED] Question about Reserved room variables !!!

Post here your questions about the Flash / Flex / Air API for SFS2X

Moderators: Lapo, Bax

Post Reply
secret007
Posts: 58
Joined: 29 May 2009, 06:27

[SOLVED] Question about Reserved room variables !!!

Post 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 ...
Last edited by secret007 on 14 Mar 2012, 08:38, edited 1 time in total.
======================================================
Choose a job of your choice and you will never have to work in life !!!
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Question about Reserved room variables !!!

Post 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.
Lapo
--
gotoAndPlay()
...addicted to flash games
secret007
Posts: 58
Joined: 29 May 2009, 06:27

Re: Question about Reserved room variables !!!

Post 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 ???
======================================================
Choose a job of your choice and you will never have to work in life !!!
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Question about Reserved room variables !!!

Post 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"
Lapo
--
gotoAndPlay()
...addicted to flash games
secret007
Posts: 58
Joined: 29 May 2009, 06:27

Re: Question about Reserved room variables !!!

Post 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.
======================================================
Choose a job of your choice and you will never have to work in life !!!
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Question about Reserved room variables !!!

Post 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.
Paolo Bax
The SmartFoxServer Team
secret007
Posts: 58
Joined: 29 May 2009, 06:27

Re: Question about Reserved room variables !!!

Post 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 :)
======================================================
Choose a job of your choice and you will never have to work in life !!!
Post Reply