Locking of a room once game start

0 votes

After connecting and joining room,  i am waiting for atleast one more player to join the room before we two start the game. I want to wait for max 15 secs so that more than 2 players can also join the room and start the game together. Now problem is i have given max users as 10, after 15 secs if joined users say less than 10 join the room. Now i want my room to be hidden or unavailable, so that new users coming will not enter the same room and create a new room to follow the same process of waiting for more players and entering together.

Suggest me how to do this thing?

asked Aug 8, 2014 in AppWarp by sahil (10 points)
recategorized Feb 13, 2015 by sushil

1 Answer

0 votes
Hi Sahil,

You can use room properties and joinRoomWithProperties to achieve this scenerio.

Firstly, you can create a room with property 'lock' as 'false'.

Once 2nd player has joined the room, you can start a timer for 15 secs and after that time is elapsed, you can set  'lock' property as 'true'.

And while joining the room, you can call joinRoomWithProperties() whose 'lock' property is 'false'
answered Aug 8, 2014 by NaveenGShephertz (244 points)
Exactly that is what I am trying to do, but i am unable to update the room property.
What i have used is given below:
1: local roomPropertiesTable = {}
    roomPropertiesTable["result"] = "";
    roomPropertiesTable["lock"] = "0";
    ROOM_ADMIN = USER_NAME
    appWarpClient.createTurnRoom ("TicTacToeRoom", ROOM_ADMIN, 2, roomPropertiesTable, 30)

and then
local roomPropertiesTable = {}
            local removeArray = {}
            roomPropertiesTable["result"] = "";
            roomPropertiesTable["lock"] = "1";
            appWarpClient.updateRoomProperties ( roomID ,roomPropertiesTable ,removeArray )
appWarpClient.addNotificationListener("onUserChangedRoomProperty", scene.onUpdateRoomProperties  )
But it is never coming back to the listener.
Hi Sahil,

Are you getting onPropertyUpdateDone() callback on RoomRequestListener? If yes, then what is the result code are you getting?

Also suggest you to set the listeners before updating the properties.
Hi,

I have added notification listener before anything done in enterscene only.

Full steps i have followed are:
1:  appWarpClient.addRequestListener("onConnectDone", scene.onConnectDone)  
  appWarpClient.addRequestListener("onDisconnectDone", scene.onDisconnectDone)  
  appWarpClient.addRequestListener("onJoinRoomDone", scene.onJoinRoomDone)  
  appWarpClient.addRequestListener("onCreateRoomDone", scene.onCreateRoomDone)  
  appWarpClient.addRequestListener("onSubscribeRoomDone", scene.onSubscribeRoomDone)  
  appWarpClient.addNotificationListener("onUserJoinedRoom", scene.onUserJoinedRoom)
  appWarpClient.addNotificationListener("onGameStarted", scene.onGameStarted)
  appWarpClient.addNotificationListener("onUpdateRoomProperties", scene.onUpdateRoomProperties)

2: Create room using:
 local roomPropertiesTable = {}
    roomPropertiesTable["result"] = "";
    roomPropertiesTable["lock"] = "0";
    ROOM_ADMIN = USER_NAME
    appWarpClient.createTurnRoom ("TicTacToeRoom", ROOM_ADMIN, 2, roomPropertiesTable, 30)


3: I join the room as:
function scene.onCreateRoomDone(resultCode, roomId, roomName)
  if(resultCode == WarpResponseResultCode.SUCCESS) then
    isNewRoomCreated = true;
    appWarpClient.joinRoom(roomId)
  else
    statusText.text = "onCreateRoomDone failed"..resultCode
  end  
end

4: Subscribe the room using:
function scene.onJoinRoomDone(resultCode, roomId)
  if(resultCode == WarpResponseResultCode.SUCCESS) then
    appWarpClient.subscribeRoom(roomId)
  end
end

5: Update the room property
function scene.onSubscribeRoomDone(resultCode, roomId)
 if(resultCode == WarpResponseResultCode.SUCCESS) then
  ROOM_ID = roomId;
                  local roomPropertiesTable = {}
   local removeArray = {}
   roomPropertiesTable["result"] = "";
   roomPropertiesTable["players"] = tostring(totalPlayers);
   appWarpClient.updateRoomProperties(roomID ,roomPropertiesTable ,removeArray)
      end
end

6: function scene.onUpdateRoomProperties(resultCode , roomTable )
 print("\n\n\n i am in update table properties")
 --print(roomTable.lock)
end


I have given my full step implementation and it is working upto the onSubscribeRoomDone() function.
After that it is calling the updateRoomProperties() function, but i am not getting the response in listener.
Is my listeners are correct, i tried using onPropertyUpdateDone also, still no response in that.

Thanks,
sahil
"onUpdateRoomProperties" is a response
so you need to register it as following

appWarpClient.addRequestListener("onUpdateRoomProperties", scene.onUpdateRoomProperties)  

You can define it in your code as
function onUpdateRoomProperties(resultCode, roomTable)

"onUserChangedRoomProperty" is a notification. So you need to register it like

 appWarpClient.addNotificationListener("onUserChangedRoomProperty", scene.onUserChangedRoomProperty)

You can then define it as
function onUserChangedRoomProperty ( username , roomid , propertyTable , lockTable )
Ok Sir,

Thanks, i got my mistake, i was using NotificationListener instead of ResponseListener.

Can you do me a favour, Can you please tell me how to use:
appWarpClient.updateRoomProperties(roomID ,roomPropertiesTable ,removeArray), because in response i am getting 4 means Bad_Request.
Hi sir,

I got the solution, I have updated the PropertiesTable and check it through getLiveRoomInfo().

I have Another Querry: Can you please tell me how can i manage the users on the table, If i have six players sitting on the table and 4th one left, how to show the position as empty, so that another can can join in now and sit idle and can start the game once the current round gets over.
Such logic is specific to the game and hence you will have to come up with a custom solution for this. You can use properties and lock/unlock them to achieve this. However how you use these APIs is up to you.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...