Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

How can I see the amount of players that are currently playing my game?

Discussion in 'Project Tiny' started by nimauke, May 3, 2019.

  1. nimauke

    nimauke

    Joined:
    May 18, 2018
    Posts:
    7
    Hello!
    I have a highscore game and want to multiply the current score of the player by the amount of other players that are playing the game at the same time.
    Is there any way I can see how many people are playing my game at the current time and use this data to multiply the score?

    Thank you
     
  2. Rupture13

    Rupture13

    Joined:
    Apr 12, 2016
    Posts:
    130
    There is no standard functionality to do this in Tiny. You could do it, but then you'd have to build that yourself using databases and stuff.

    You'd then carefully have to determine when a player is actually considered "playing" your game. Is that when he has started the game? When he is still on the webpage? By sending life-ticks to the database?
     
    reallyhexln likes this.
  3. reallyhexln

    reallyhexln

    Joined:
    Jun 18, 2018
    Posts:
    69
    I agree with Rupture13, you definitely need your own server side.
    Tiny is just a client, there are no multiplayer features and the browser will not allow you to share user data between multiple clients due to browser security restrictions.

    You can send in-game request to server when new player is started the game via ajax (see xmlhttprequest reference).
    You also will need to make requests for all in-game critical events like a gameover / gamepause / timeout / windowout / windowin / etc - to determine if user still playing the game.
    Finally, your server will need to send updatestate event (that will contain current players count) to all active players when players count was changed.
     
    Last edited: May 3, 2019
    Zionisias likes this.