Create a GameRoom question

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

charles
Posts: 13
Joined: 23 Feb 2013, 09:08

Create a GameRoom question

Postby charles » 12 Oct 2013, 17:46

Hi,
The question is:

The client is send a "CreateSFSGameRequest" request ,
API http://docs2x.smartfoxserver.com/api-docs/csharp-doc/Index.html
said it will fire ROOM_ADD ,or ROOM_CREATION_ERROR if it has problem
BUT,
ROOM_ADD was not fired and JOIN_ROOM was fired

this is room settings :
GameSettings setting =new SFSGameSettings("roomname");
setting.MaxUsers=2;
setting.GroupId="Games";
setting.LeaveLastJoinedRoom=false;
setting.IsPublic=true;
setting.MinPlayersToStartGame=2;
setting.NotifyGameStarted=true;
setting.Variables.Add(new SFSRoomVariable("costrange",123));


I checked client has subscripted the groupId ,and the forums not find about this issue.
please someone can help me, thanks :(

API version 1.3.0
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Create a GameRoom question

Postby Lapo » 14 Oct 2013, 09:06

Sounds strange. Can we see the entire code snippet that creates the Room and how the event handlers are added?

Thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
charles
Posts: 13
Joined: 23 Feb 2013, 09:08

Re: Create a GameRoom question

Postby charles » 14 Oct 2013, 17:20

thanks your reply,Lapo
I get the answer myself. :D

I lost to send Subscrpit Request.....
charles
Posts: 13
Joined: 23 Feb 2013, 09:08

Re: Create a GameRoom question

Postby charles » 14 Oct 2013, 17:35

Oh, the other problem occur, :oops:
the same setting:

Code: Select all

SFSGameSettings setting =new SFSGameSettings((string)ht["roomname"]);
      setting.MaxUsers=2;
      setting.GroupId="Games";
      setting.LeaveLastJoinedRoom=false;
      setting.IsPublic=true;
      setting.MinPlayersToStartGame=2;
      setting.NotifyGameStarted=true;
      setting.Events=new RoomEvents();
      setting.Events.AllowUserEnter=true;
      setting.Events.AllowUserExit=true;
      setting.Events.AllowUserCountChange=true;
      setting.Events.AllowUserVariablesUpdate=true;
      
      //variables
      setting.Variables.Add (new SFSRoomVariable("creatorID",_instance.sfc.MySelf.Id));
      setting.Variables.Add(new SFSRoomVariable("costrange",123));
      setting.Variables.Add(new SFSRoomVariable("cost",735));
      _instance.sfc.Send(new CreateSFSGameRequest(setting));

ROOM_ADD  callback :
void OnRoomCreated(BaseEvent e){
      SFSRoom newRoom=(SFSRoom)e.Params["room"];
      print ("ROOM_ADD:"+newRoom.Name+" created success");
      print (newRoom.GetVariables().Count+",p:"+newRoom.PlayerList.Count);
   }


I was set 3+1 variables in room ,
and ROOM_ADD event work fine,
but ,when I was access the params room,
It was 1 variable, user in room was 0!
strangely,it sometimes work fine ->4 variables and 1 user.


please help me , I must be finish this game project before December... :oops:
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Create a GameRoom question

Postby Lapo » 14 Oct 2013, 18:08

When you receive the ROOM_ADD event you haven't joined the Room yet. So it's ok to see that it contains zero users.
You will receive the ROOM_JOIN even after that.

To check the status of Room Variables use the ZoneMonitor in the Admin Tool, select the right Room and see which variables are available
Lapo

--

gotoAndPlay()

...addicted to flash games
charles
Posts: 13
Joined: 23 Feb 2013, 09:08

Re: Create a GameRoom question

Postby charles » 15 Oct 2013, 02:56

I know that you said,
the problem alawys occur at after ROOM_ADD and before JOIN_ROOM.
I checked ZoneMonitor ,roomvariables was fine.
The variables needs to set "IsPersistent=true" or other setting?
And the other problem,
userA create a SFSGame ignore the variables problem,
userB use smartfox.GetRoomListFromGroup("Games") to find it ,but check "room.playerList" or "room.userList" ,their Count attribute is 0
and check "room.UserCount" is 1. :?:

Should I use CreateRoomRequest to replace CreateSFSGameRequest?
Or coding server side extension additional to process room problems ?

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

Re: Create a GameRoom question

Postby Lapo » 15 Oct 2013, 08:40

I think you are missing a few concepts here that are fundamental.

When you subscribe to a Group of Rooms you get the list of all Rooms inside that group.
Because you haven't joined any of those Rooms your client didn't receive the user list of those Rooms. In other words you receive a Room's user-list only when you join it, otherwise the user-list will always be empty. The Room user count serves the purpose to keep you updated about the number of players and spectators in Rooms that you haven't joined.

Similarly this applies to RoomVariables. Those values are available only to the people that have joined the Room, not those outside of it.
There is however an exception to this. Global RoomVariables are propagated to everyone outside the Room as well.

Make sure to learn the details in the docs:
http://docs2x.smartfoxserver.com/Develo ... chitecture
http://docs2x.smartfoxserver.com/Develo ... -variables
Lapo

--

gotoAndPlay()

...addicted to flash games
charles
Posts: 13
Joined: 23 Feb 2013, 09:08

Re: Create a GameRoom question

Postby charles » 15 Oct 2013, 12:30

thank you Lapo ,
thanks your direction. :D

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 48 guests