Some notes before we get inside the explanation:
- The coding format of the leaderboard hologram is much more different and intricate than the leaderboard scoreboard. Mainly because of how the scoreboard worked.
- There are different ways to code this other than my method such as BallPen’s, Hxncus’s, McMaster’s, etc… but they both had the same issues and just technically used the same format and made some changes to the source code. Mine is pretty different and distinct from others, it is also the most accurate and relatable method for now as well.
- For people who don’t understand why the name of the thread contained “not infinite” is because a few days ago I and McMaster were working on a way to make a self-generate position leaderboard (using hologram and scoreboard). It basically generates and assigns positions 1, 2, 3, etc… to each individual that had at least logged in the world once. In brief, I put it inside the name to prevent misapprehension and confusion, and thinking infinite and not infinite are the same thing.
- I recommend checking out AtomSeis’s tutorial about dynamic variables and variable API tags first for a better understanding of this code by clicking here.
Now after you had finished reading all the notes let’s hop on the explanation.
Format of it:
If not inverse proportion:
» Top 1:
Function (a) {
If variable compare number Top 1 value variable < (x)
If variable %player% or %selected% != Top 1 name
Set variable Top 1 back up value variable = Top 1 value variable
Set variable Top 1 back up name variable = Top 1 name variable
Set variable Top 1 value variable = (x) variable
Set variable Top 1 name variable = Game value[“Current name of player”]
Set variable Top 2 value variable = Top 1 back up value variable
Set variable Top 2 name variable = Top 1 back up name variable
Else
Set variable Top 1 value variable = (x) variable
Set variable Top 1 name variable = Game value[“Current name of player”]
}
» Top 2, Top 3, … Top n:
Function(a(n)) {
If variable compare number Top n value variable < (x) < Top n-1 value variable
If variable %player% or %selected% != Top n name
Set variable Top n back up value variable = Top n value variable
Set variable Top n back up name variable = Top n name variable
Set variable Top n value variable = (x) variable
Set variable Top n name variable = Game value[“Current name of player”]
Set variable Top n+1 value variable = Top n back up value variable
Set variable Top n+1 name variable = Top n back up name variable
Else
Set variable Top n value variable = (x) variable
Set variable Top n name variable = Game value[“Current name of player”]
}
If inverse proportion:
» Top 1:
Function(a) {
If variable compare number Top 1 value variable > x
If variable %player% or %selected% != Top 1 name
Set variable Top 1 back up value variable = Top 1 value variable
Set variable Top 1 back up name variable = Top 1 name variable
Set variable Top 1 value variable = (x) variable
Set variable Top 1 name variable = Game value[“Current name of player”]
Set variable Top 2 value variable = Top 1 back up value variable
Set variable Top 2 name variable = Top 1 back up name variable
Else
Set variable Top 1 value variable = (x) variable
Set variable Top 1 name variable = Game value[“Current name of player”]
}
» Top 2, Top 3, … Top n:
Function(a(n)) {
If variable compare number Top n value variable > (x) > Top n-1 value variable
If variable %player% or %selected% != Top n name
Set variable Top n back up value variable = Top n value variable
Set variable Top n back up name variable = Top n name variable
Set variable Top n value variable = (x) variable
Set variable Top n name variable = Game value[“Current name of player”]
Set variable Top n+1 value variable = Top n back up value variable
Set variable Top n+1 name variable = Top n back up name variable
Else
Set variable Top n value variable = (x) variable
Set variable Top n name variable = Game value[“Current name of player”]
}
If you are trying to make like Top n ← Top 1 (n > 1) instead of Top n → Top 1 then simply change the variables’ names. I will be explaining with Top n → Top 1 instead for an easier understanding.
Priorities:
This is the most important step and also the step where a lot of coders failed to find the problem within their code. It basically controls which top (n) will be triggered first. For instance:
Top n >> Top n-1 >> Top 1 (a)
II (or)
Top 1 >> Top n-1 >> Top n (b)
The format I said above only works if the first priority method (a) is utilized. The reason is the top n-1 and top n will get overwritten by either top 1 or top n-1 if you try to use the second priority method (b).
Explanation:
Now I will explain how this code even works in the first place. Basically, I have an operation like this:
Player event left click
Set variable %player%click += 1
So every time the player left clicks it will trigger the player event left click operation and it gonna increase their %player%click’s value by 1 using set variable +=.
Next, I will have a function called (a). By utilizing the “Top 2, Top 3, … Top n” method I said above we will have a code that looks like this:
Function(a) {
If variable compare number Top 3 value variable < %player%click < Top 2 value variable
If variable %player% or %selected% != Top 3 name
Set variable Top 3 back up value variable = Top 3 value variable
Set variable Top 3 back up name variable = Top 3 name variable
Set variable Top 3 value variable = %player%click variable
Set variable Top 3 name variable = Game value[“Current name of player”]
Set variable Top 4 value variable = Top 3 back up value variable
Set variable Top 4 name variable = Top 3 back up name variable
Else
Set variable Top 3 value variable = %player%click variable
Set variable Top 3 name variable = Game value[“Current name of player”]
}
4 = n + 1
3 = n
2 = n - 1
Function named “a” will check whether if the %player%click’s value is greater than the current Top 3 variable’s value and smaller than Top 2 variable’s value (Top 3 value variable < %player%click < Top 2 value variable). Then it checks whether your name is != Top 3 name (If variable %player% or %selected% != Top 3 name) to prevents from value overwrite on both top 3 and top n+1(4). After that, it assigns 2 variables with the name “Top 3 value variable” and “Top 3 name variable” to 2 back up variables named “Top 3 back up value variable” and “Top 3 back up name variable” respectively. These 2 variables are used to prevent the top n’s value and name overwrite the top n-1’s value and name. Example:
Top 3 value variable = “10”
Top 3 name variable = “deefer”
Top 2 value variable = “15”
Top 2 name variable = “beefer”
If we increase the Top 3 value variable by 6 then the Top n value variable > Top n-1 value variable by 1. Now we gonna try assigning the Top 3 variable to the Top 2 variable and the Top 2 variable back to the Top 3 variable without using the Top 2 backup value and name variables then it gonna look like this:
Top 3 value variable = “16”
Top 3 name variable = “deefer”
Top 2 value variable = "16"
Top 2 name variable = "deefer"
If we use backup value and name variables then it gonna show like this:
Top 3 value variable = "15"
Top 3 name variable = "beefer"
Top 2 value variable = "16"
Top 2 name variable = "deefer"
If you still did not understand then let me put the backup name and value variables for a thorough explanation:
Top 3 value variable = “10”
Top 3 name variable = “deefer”
Top 2 value variable = “15”
Top 2 name variable = “beefer”
Save the Top 2 value variable and Top 2 name variable within the Top 2 backup value variable and Top 2 backup name variable:
Top 2 backup value variable = “15”
Top 2 backup name variable = “beefer”
Now increase the Top 3 variable’s value by 6 we will have 16
Top 2 value variable = “16”
Top 2 name variable = “deefer”
Assigning the Top 2 backup value and name variables to the Top 3 value and name variables we will have:
Top 3 value variable = "15"
Top 3 name variable = "beefer"
Top 2 value variable = "16"
Top 2 name variable = "deefer"
Now after you understand how the assignment works. It is time to explain how the else part works:
Else
Set variable Top 3 value variable = %player%click variable
Set variable Top 3 name variable = Game value[“Current name of player”]
Else basically changed a statement from true to false and vice versa. Example:
If variable != >> else >> If variable =
What else does here is basically prevent the top n’s variables from consecutively assigning back to the top n+1’s variables every time the %player%click’s value got changed. So the values of both of them don’t match each other.
Other methods:
- Arrays
- Same as this method but instead of else we can use loops
- Entities (not recommend)
Summarise:
Leaderboard hologram is regarded as one of the most lengthy, complicated, and difficult codes out there. Challenges best coders namely BallPen, McMaster, TheSuperiorXMod9, etc… Yet the solution to fix it is very simple, 2 backup variables to prevent top n and top n+1 overwriting each other. I hope this helped despite I have seen lots of players start asking how to code this code from seeing it inside nasok and egor’s world.