Displaying and Sorting a Leaderboard

Hi, I’m very new to Thunkable and app-making in general. I’m only three days in, actually. I’ve tried searching extensively before posting this, so my apologies if the answer is somewhere else.

I’m trying to make a leaderboard that is generated from within the app itself. A user creates a score for an object, and as objects are created, I’d like to display a leaderboard that automatically sorts the objects in descending order with the highest score on top.

Can someone please point me in the right direction? Thank you so much. I’ve already learned a ton in the past two days from this community.

Hi @andetomrkzp, welcome to Thunkable!

Are you wanting to create a local leaderboard (high score list) that is limited to the device? Or do you want the leaderboard to include scores from other users on other devices as well?

1 Like

Thanks for the quick reply!

I want to create a local leaderboard limited to the device, at least for now.

Okay. That “for now” is important but if you use a list, as I suggest, you can later modify it to save data to Firebase and compare with other users’ scores.

The basic idea would be to create a stored variable that is an empty list. Then, when the user creates a score, you add the score to the list and sort the list. There are blocks for this in the List drawer. If you don’t know which to use, just ask. For multiple objects, use multiple lists.

2 Likes

Hmm, I’ve been trying to wrap my head around it and trying lots of different things, but I’m just not getting it. How do you add the user’s score to a list?

To add a value to a list and then sort the list, do this:

Obviously, you’d have to set the player score somewhere else first so it’s not just zero.

Lots more here: Thunkable On Air Episode 1: How to use Lists - YouTube

3 Likes

Thanks for that. Your post and that video were really helpful, but is there a way to have the object’s name sort along with its score? I’d like to show one column with the scores and next to that a column with the names of the objects.

I’ve also learned a lot from Darren’s How to Sort a List of Objects video, but I can only make it work with a stored variable like his “INITIAL_LIST” example. I can’t figure out how to create an object with fields where those fields are variables themselves. It just gives me an error message. I know there’s an answer somewhere between your suggestions and Darren’s video, but I can’t figure it out yet.

1 Like

Yeah, @darren’s videos are great.

For creating a pair of values (name+score), I’d probably use two lists. If you need more fields than that (e.g. name+score+price+size), I’d usually start using a data source at that point. With two lists, you’d have to get a little creative about sorting the “name” list because you can’t sort it the same way. That’s where sorting a spreadsheet makes things easier, I think.

I really haven’t done much with object creation. @darren might be able to say more about that. I’m familiar with objects from JSON and Firebase but I don’t typically create the data structures as much as just access them.

2 Likes

Ok, I’ll see what I can do. Thanks again for all of your help!

I know this is a old post, and dont expect an answer, but did you end up creating it? Im stuck on the same thing now, (name+score) and displaying in either first, second, or third place on a leaderboard screen. Trying to do it using lists, but its all a little confusing trying to get it to work.

Thought Id try my luck, thanks!

Maybe contact @tatiang directly if you want a code sample as the user associated with this post hasn’t been online in over 3 years

1 Like

Are you planning to use a leaderboard just for your device, or you want it to be shared with all the users (online)?

Also it would be great if you can share your blocks, so it’s easier for the community to help you out

thank you!

1 Like

I didnt know I could contact directly, my apologies.

Heres the link to my project so far, Its just for a college project, and it should just be on that device that is used. For marking purposes, i assume it will have to work on various different devices, (mainly computers) and should only store on that device.

https://x.thunkable.com/copy/1569c581c6fe8d708fce2c67bc60b9e7

Im not sure how the lists work, and if the scores would be saved regardless if you open /close it, but preferably if i play 5 times in a row, then just the top 3 scores + names they entered with the coresponding score.

Thanks for replying!

There are many solutions for your question, the one i suggest to follow is this one.

Since you need an online leaderboard that everybody from different devices can see and be updated realtime for everybody, i suggest using Airtable component as it’s very easy to set up and requires minimum effort.
Of course there are many else, i’m sure someone from the community can show you some more.

You can easily create your Airtable’s workspace here if you haven’t done it yet.

Once set the database, in your case simple columns “Name” and “Score”, you can click on “Sort 9 → 1”

Airtable will also sort them automatically once a new record is added, keeping the leaderboard always updated.

image

Hope it helps

1 Like

Thanks for the help!

Would It be easier to keep the storing device specific? What I meant by my last comment was say if I play on my college computer to test if it works, and I play 4 times, it stores all 4 attempts onto the leader board at the end screen. But then I have to hand it in to my lecturer, and they play it on their computer, it would have 0 attempts as mine and the lecturer devices are separate but would store their attempts. Not like a online leaderboard which connects mine and theirs so we can see eachothers if you get me.

I think I over complicated things in my honest opinion. Im sure its supposed to be miles easier than this, so I want to try and make it a bit easier as the deadline is coming up lol.

If this helps, you might want to save all the data in a separate spreadsheet. I ran into the same problem in my app that I have been working on and I used google sheets to save every all the data from each input.

However, if there is a problem with your variables try using a stored or cloud variable instead of an app variable.

1 Like