How do I display current user position in leaderboard?

0 favourites
  • 10 posts
From the Asset Store
A small template showing how to build a firebase ranking
  • Hi Everyone,

    I am currently trying to create leaderbaord by following this tutorial "https://www.scirra.com/tutorials/4839/creating-your-own-leaderboard-highscores-easy-and-free-php-mysql"

    Can anyone please tell me how to display position of ranking of current user/scorer. (I.e. If current user is standing at ranking 101th position in leaderboard then how to display the ranking(101th) below 10 top scores table.

    sample capx is attached in the tutorial itself. I am using same.

    Need help very urgently.

    Regards,

    Jatin

  • You should be able to have the MySQL engine sort the results of a SELECT script.

    Like this:

    https://www.tutorialspoint.com/mysql/my ... esults.htm

  • You should be able to have the MySQL engine sort the results of a SELECT script.

    Like this:

    https://www.tutorialspoint.com/mysql/my ... esults.htm

    Hi Thanks a lot for response.

    But I have no knowledge about php and mysql. I was following sample capx file used in tutorial. Currently it is displaying only two columns, name and score. Can you help me in displaying 3rd element which is ranking. In sample author has used array. How can I turn it to use 3 columns instead of 3. and how to fetch from db and display in construct 2 file.

    I will be really greatful to you if you can help me in modifying the sample capx of tutorial.

    Thanks in advance.

    Jatin

  • Sorry, I was under the impression that you had some knowledge of database operation.

    Okay, you see in this image:

    towards the bottom where he has the parameter $sql="SELECT * FROM scores ORDER BY score DESC LIMIT 10"

    You simply need to remove the "LIMIT 10" and it will return all of the scores in the database ordered by score descending.

    That is what that select statement is asking for:

    SELECT (tells the database to get data)

    * (tells it to return all data)

    FROM scores (from the "scores" table)

    ORDER BY score (order the data lexicographically by score)

    DESC (in a descending order from highest to lowest)

    LIMIT 10 (only return the top 10 scores)

    How can I turn it to use 3 columns instead of 3.

    Also this question makes no sense.

  • Sorry, I was under the impression that you had some knowledge of database operation.

    Okay, you see in this image:

    towards the bottom where he has the parameter $sql="SELECT * FROM scores ORDER BY score DESC LIMIT 10"

    You simply need to remove the "LIMIT 10" and it will return all of the scores in the database ordered by score descending.

    That is what that select statement is asking for:

    SELECT (tells the database to get data)

    * (tells it to return all data)

    FROM scores (from the "scores" table)

    ORDER BY score (order the data lexicographically by score)

    DESC (in a descending order from highest to lowest)

    LIMIT 10 (only return the top 10 scores)

    > How can I turn it to use 3 columns instead of 3.

    >

    Also this question makes no sense.

    Thanks a lot Gumshoe for such details replay, really really helpful and I understood that removing the limit of 10 will display all results. But in sample capx creator is using array and I have made it 10x10 to display data in 5 lines in text boxes. If I will try to show all list (might be scrolable) then how it can be done (I think it needs to create scrollalbe list with data filling from server, right)? any help in this? To cut short the things I am sharing screenshot of leaderboard similar to my requirement. I will be very thankful to you if can help me in getting close to this.

    Regarding colum 3 to 3 statement, it was my mistake. Actually creator is using 2 column (through array) and I need 3 colmn (index no. , player name, score). Also explaining this through screenshot.

    Thanks again.

    waiting for your reply. below is screenshot of required leader board and question which I have.

  • It's easy, first display that top 10 select. Under it add another textbox or whatever C2 object you use to display the first 10, so add one under it (i guess it's a textbox).

    Make it smaller and assign the following select to it

    SELECT

    *

    FROM scores

    where Name = <C2 variable holding his nickname>

    This will display one line with the player's nickname, and since you put the textbox under it, it will show as separate.

    It is possible to make a select to display everything in the same C2 object but i'm in a bit of a hurry right now. I'll see if I can make that work as well a bit later.

  • gumshoe2029 i really hope those are not your real DB credentials

  • It's easy, first display that top 10 select. Under it add another textbox or whatever C2 object you use to display the first 10, so add one under it (i guess it's a textbox).

    Make it smaller and assign the following select to it

    SELECT

    *

    FROM scores

    where Name = <C2 variable holding his nickname>

    This will display one line with the player's nickname, and since you put the textbox under it, it will show as separate.

    It is possible to make a select to display everything in the same C2 object but i'm in a bit of a hurry right now. I'll see if I can make that work as well a bit later.

    Hi,

    Thanks for response. As I shared above I hve no idea about php and sql. Can you help me by updating sample capx (of tutorial) to the one showing current user id? That will be big help for me.

  • gumshoe2029 i really hope those are not your real DB credentials

    Not my database, so not my problem. :-p

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • jatin1726

    I actually ran into this same problem, and I found a clever solution from someone whose handle I forget now...

    But here you go:

    https://drive.google.com/open?id=0B-xiq ... mliTUJ1SGM

    To get your player at the bottom just add another Text field and use Array.At(Array.indexOf(playerName)) & ": " & myScore.

    Or you could even use a 2D array and store as many other columns as you need in your array, just use the X=0 column to store your indices (like player id).

    SELECT

    *

    FROM scores

    where Name = <C2 variable holding his nickname>

    You should use caution in using this unless you can guarantee that your nicknames are unique, otherwise confusion will ensue. Most databases use a player index or player id to ensure uniqueness in your database keys.

    If you have two players named "jatin" then that SQL statement will return two rows of data! Will the real jatin please stand up?

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