How do I make an online player/score counter?

0 favourites
  • 9 posts
From the Asset Store
Players follower. use it for anything which follows the player
  • Hi everyone,

    Here is a topic to ask you some very simple but that is a great pain for me...

    I would like to do on my layout a players counter and a total score counter (=total of all the scores of all the players).

    I know there are a lot of ajax tutorials out there (I've read most of them) but it is mainly about highscores.

    Me, I just would like to display : XXX players have played the game and have scored XXXX

    That's all

    So ideally, it would be just a html/php file store on my online serveur and each time a player play/score, it adds the variables to the file (I just need the total).

    I get the overall principe of use of Ajax but I don't know which Ajax and PHP I should use...

    Thanks in advance and sorry if my question have been already answered (but I don't now where).

  • Hi there, give me a couple of hours. I'll put together a tutorial that will handle that for you. First a few questions/suggestion.

    1) Are you authenticating the player? or they just type in any name. In the latter case each player can have infinite names.

    2) Server-side storage. I strongly suggest MySQL database just in case you end of having millions

    3) Front-end are you going to display the scores in game or online or both?

    Please answer back quickly if possible since I am starting the project now.

  • HI,

    I hope I'm not too late...

    Thank you so much for your answer!

    My idea was to do something simple such as:

    • A PHP file with 2 numbers where you can adds variable from the game

    For example (but of course it's not correct)

    <?PHP

    Total score: 465

    Total players: 26

    ?>

    • A construct request for which each time the player start a game, it display in a text box the total score and the total of players/game played
    • A construct request for which each time a player finish a game, it add automaticly to the php file his score and and +1 (to the players counter)

    So to answer to your answers:

    1) No need for personnal autotification. As I said, all the scores should be added together. But of course that would be a plus in addition (but not mandatory)

    2) Here also, as everything will be merge together, I don't really need a database for each score. But again, As said beyond, if it is possible (and simple), sure

    3) The score are going to be display in game so far. But it wil be nice to have access to the stored file if I need to change/add variable

    I hope I'm clear enough. You know better than me anyway

    Thank you again!

  • ok, thanks for response.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • No thank you to you for your help ^^

  • wow I have it 98% done and i was stuck on on getting the Player name and score in/out of C2 when I closed C2 without saving the template started from a a project OUCH! So the only working somewhat copy is up at c2 dot i2tmlabs dot /c2scores/

    However i did come across a Plugin someone had already made in 2012. Did you see this?I think what I am doing is better so i will complete it, just got to start the C2 part again from scratch. The javaScript, PHP and MySQL are all working. But try that URL for now and I'll post mine when its done.

    scirra.com / tutorials / 346 / online-high-score-table-ajax-php-mysql

  • HI,

    Sorry for the late anwser, my VPN (I'm in China) was down...

    Thanks again for your answer and all the efforts

    I've already read this very interesting tutorial. However, as I explained, it is more about highscore implementation.

    Me I really only want to display the total score of all the players together....

    So much more simple (but still too difficult for me )

  • I think I would use a highscore table still using a mysql database.

    Then you can use the SUM function in your mysql query to get the total score.

    To get the total players, or games played you can use mysqli_num_rows. That function will output the total number of rows/entries.

    Another option is to use a flat file system in php to create a file that you add to, only storing the information you want. Starting with fopen Then you would use fwrite and I would probably use an explode so I could store both variables in one file.

  • No problems. I'll pit my version up when complete. Think ill try and addon.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)