IMPORTANT: online multiplayer game leaderboard with Firebase.

120 views
Skip to first unread message

Kate Murry

unread,
Dec 3, 2019, 9:17:52 AM12/3/19
to MIT App Inventor Forum

Hi everyone! I’m developing an online multiplayer game with App Inventor, but now I have a big issue that I can’t solve: the high scores leaderboard.

I use Firebase as database, although I’m not sure it’s the most suitable database (alternative tips are welcome).

 

Can someone help me?

 

Thank you so much!

ABG

unread,
Dec 3, 2019, 11:52:13 AM12/3/19
to MIT App Inventor Forum
See https://docs.google.com/document/d/1M2xhgDF5c59ILsJqB3lGAlgItd89UAzXnNqCgWKke5g/edit?usp=sharing
for how to sort and insert the scores and names, but in TinyDB.

FireBase is a bit harder, because you might have to
worry about two people getting a high score at the same time,
and one person's read/write cycle overlapping the other's read/write cycle.

You can minimize that problem by keeping the local copy of the high score list fresh.

ABG

Kate Murry

unread,
Dec 5, 2019, 4:11:36 AM12/5/19
to MIT App Inventor Forum

I tried to apply this solution to my project with Firebase, but it don’t works.

I found another solution which works partially, that is I can get only the high scores ranking, but when I try to add the name and the position index, I’m in trouble.

 

For example, suppose we have the following results:

 

Mark – 800 points

Eric – 500 points

Robert – 1100 points

Luke – 200 points

 

On my listview will appear a ranking like that:

 

1:____Robert____1100

1:____Eric____1100

2:____Mark____200

1:____Eric____1100

2:____Robert____500

3:____Luke____200

1:____Eric___1100

2:____Robert____800

3:____Luke____500

4:____Mark____200

 

How could I fix this? I attach my project screens.

 

Thank you.

1.png
2.png
3.png
4.png
5.png
6.png

TimAI2

unread,
Dec 5, 2019, 4:46:10 AM12/5/19
to MIT App Inventor Forum
Are you storing all game scores in Firebase for player or just the last / highest ?

e.g.

- Mark
  - 800
- Bob
  - 1100

or

- Mark
  - 800, 600, 900
- Bob
  - 1100, 700, 1200

Kate Murry

unread,
Dec 5, 2019, 4:57:45 AM12/5/19
to MIT App Inventor Forum
I store just the highest score for each player.

TimAI2

unread,
Dec 5, 2019, 5:34:47 AM12/5/19
to MIT App Inventor Forum
Something like this then: (see attached screen and blocks images)

What are we doing?:

  1. Fetch the taglist
  2. Fetch the value for each tag and combine it with the tag (name)
  3. While doing 2 above, we set leading zeros to each score (5 digits in this case, but should always be one bigger than the biggest score)
  4. Why, because we then sort the list as TEXT (not numbers)
  5. Display the leaderboard





screenleaderboard.png
leaderboard.png

Kate Murry

unread,
Dec 5, 2019, 8:07:42 AM12/5/19
to MIT App Inventor Forum

This solution works pretty well using Label, but unfortunately don’t works with ListView. 

TimAI2

unread,
Dec 5, 2019, 8:40:21 AM12/5/19
to MIT App Inventor Forum
Add and amend your blocks:

blockslvleaderboard.png


screenlvleaderboard.png



Kate Murry

unread,
Dec 5, 2019, 10:45:05 AM12/5/19
to MIT App Inventor Forum
IT WORKS! Thank you so much! ;-)
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages