onUserJoined is not executed for local player?

0 votes

Hi Rajeev

You said best place to start a game is onUserJoined but I guess something wrong here. First of all no problem creating max 2 user room. You said "Whenever you get the onUserJoinedRoom event, check the user name, if it is not you then there is a second user in the room, hence you can start the game. In this way, there is no need to call getLiveRoomInfo to detect the second user."

Firstly, onUserJoinedRoom is not executed when local player joins room accourding to my test. It is executed when other players joins room. So checking name of joined user will never be my name. Second problem, there may be already a player inside room and in this case I am the second player. Again in this case onUserJoined room will never called so that I can start game there!!! Am I right?

related to an answer for: When to start game
asked Jan 5, 2016 in AppWarp by gokhan (20 points)

1 Answer

0 votes
Hello Gokhan,

Yes, the onUserJoinedRoom will not be called for the user himself as he has not yet subscribed for the room. But, the user who joins the room first will get this callback for the second user. So, always the first user in the room can start the game.

If your game is a turn based game then when one user calls startGame then both users in the room will get onGameStarted callback.

If your game is not a turn-based game then user, who wants to start the game, can send game start message using sendChat or sendUpdatePeers method. In response both the users will receive the corresponding notification.

In both the cases, users will receive game start notification and then game start logic can be triggered at both the ends.

If you dont want to rely on onUserJoined callback then you can consider onJoinRoomDone or onSubscribeRoomDone as check point to start the game.

This way whenever user gets onSubscribeRoomDone(if this is the check point) then he can fire getLiveRoomInfo and if there are two users in the room then he can start the game using above described way.

I hope it will help.

Thanks.
answered Jan 5, 2016 by rajeev.etc (1,660 points)
Hmm I understood your point Rajeev. Thanks.
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
...