[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)

        }
    }


}


18 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