[FREE] LeaderBoard Extension - Sort Users Score!

With this extension, you can sort user score or balance information from high to low.

Screenshot_2

Example Blocks:

Example AIA
LeaderBoard.aia (33.7 KB)

Download AIX:
com.ruwis.leaderboard.aix (30.4 KB)

Open Source (Kotlin)

package com.ruwis.leaderboard

import com.google.appinventor.components.annotations.SimpleEvent
import com.google.appinventor.components.annotations.SimpleFunction
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent
import com.google.appinventor.components.runtime.ComponentContainer
import com.google.appinventor.components.runtime.EventDispatcher
import com.google.appinventor.components.runtime.util.YailList


class LeaderBoard(container: ComponentContainer) : AndroidNonvisibleComponent(container.`$form`()) {

    @SimpleEvent
    fun Sorted(users : YailList, scores : YailList) {
        EventDispatcher.dispatchEvent(this, "Sorted", users, scores)

    }

    @SimpleFunction
    fun SortUsers(userList : YailList, scoreList : YailList) {
        val uList = userList.toList()
        val sList = scoreList.toList()

        if (uList.size == sList.size) {

            val leaderMap : MutableMap<String, String> = HashMap()

            for (item in uList.indices) {
                val skor = sList[item].toString()
                val kullanici : String = uList[item].toString()
                leaderMap[kullanici] = skor
            }

            val sortedMap = leaderMap.toList().sortedBy { (k, v) -> v.toFloat() }.toMap()

            val users = YailList.makeList(sortedMap.keys.reversed())
            val scores = YailList.makeList(sortedMap.values.reversed())

            Sorted(users, scores)

        }
    }


}


20 Likes

useful extensions exist to add things that are not in KODULAR but also to facilitate things that can be done in KODULAR

here is one of them

1 Like

What will happen if two users have same score?

2 Likes

No problem, add both users to the leaderboard

how can we use this extension with firebase?

Get data from firebase, user and points, add them to lists, use extension

can you send me some picture of blocks how to add firebase data with sort users score? pls dont reject dora_ dora_paz

I have a doubt with this extension.
How to make a list in which the punctuation cannot be lowered, only improve it.
For example if “Jack” has 10 points, play again and get a score of 20 points. But then you only get 5 points and this is where you don’t have to put anything and follow the 20 points.

What is the difference with…

i need it too

I’m having a problem, if two users have the same name.
It only shows the score of 1

Doens’t previous js method work for you? Sorted fb tags alphabetically

It works normally, but if there are users with the same name, I get an error
Select list item: Attempt to get item number 5 of a list of length 4:

Can you show me, what did you adjust??

users with different name
Screenshot_21

two users named Kodular
Screenshot_22

I didn’t adjust the blocks, they’re still the same.

I managed to succeed that way, but I made a kludge.
When the user creates the account, I save a random number after the name, when I put it in the classification I remove only the numbering.

but there must be some way without changing my firebase structure.
Screenshot_23

please show your fb struture… I have sughgested the blocks based on your query only…

If you prepare your logic like this then it is easy to sort any type of data with js
3ynrtugft - JavaScript - OneCompiler have a look at this

My Fb :

image

My Blocks :

App Response :

(One Condition, you must enable this from settings)
image

this is an example with two users with the same name, which causes a problem with the display

As I reported earlier, I just got it that way. saving a random number after creating the account and removing the numbering in the display.

I have several scores because they are from different areas.
My issue is only if two people use the same name everything else is working fine.

Pls see my previous reply. You have answer in that. The only solution is use sorting based js, you will get exact result

1 Like