Sorting variables? (Rank System)

burntable

Veteran
Veteran
Joined
Oct 16, 2013
Messages
63
Reaction score
9
First Language
German
Hi, I'm trying to create a ranking system for my project.

NPCs fight each other when the player moves to another map or fights against another NPC.

I have several variables with the the current wins of each player.

Simple example:

Player 1:  12 wins  # $game_variables[1] == 12  -> Rank 3

Player 2:  15 wins  # $game_variables[2] == 15  -> Rank 2

Player 3:    2 wins  # $game_variables[3] == 2    -> Rank 5

Player 4:    5 wins  # $game_variables[4] == 5    -> Rank 4

Player 5:  21 wins  # $game_variables[5] == 21  -> Rank 1

Leaderboard:

Gold:     Player 5 with 21 wins

Silver:    Player 2 with 15 wins

Bronze: Player 1 with 12 wins

etc.

To give every player a rank and create a leaderboard, I would have to lay out a plethora of conditional branches.

I wonder if there's an easy way to do this?
 

MeowFace

Meow
Veteran
Joined
Feb 22, 2015
Messages
1,034
Reaction score
184
First Language
Meowish
Primarily Uses
The sorting part can be done easily using an array i guess.

You don't need  full script for that to work but you will need some script calls.

In an event script call, try this:

@ranking = [$game_variables[1], $game_variables[2], $game_variables[3], $game_variables[4]]@ranking.sort!$game_variables[6] = @ranking[0]$game_variables[7] = @ranking[1]$game_variables[8] = @ranking[2]$game_variables[9] = @ranking[3]This should give you the newly sorted numbers in Variables 6~9 (assuming you don't want to overwrite the old variables)

edit:

To get the sorting in reversed order, 

replace

@ranking.sort!with this

Code:
@ranking.sort!.reverse!
 
Last edited by a moderator:

Engr. Adiktuzmiko

Chemical Engineer, Game Developer, Using BlinkBoy'
Veteran
Joined
May 15, 2012
Messages
14,682
Reaction score
3,003
First Language
Tagalog
Primarily Uses
RMVXA
Try something like

ary=[$game_variables[1], and so on]rank={}ary.sort!(1..5).each do |i| (1..5).each do |x| if ary == $game_variables[x] rank = [x,ary] break endendNow you have a hash which saved which player is at each rank and what the score is... Showing it depends on how you want to actually show the leaderboard.This might not be the most efficient way (or might not work), I just wrote this out of my mind. XD

@meow - the problem with that is you dont have a link to which player has that score which I think he needs judging from his post.
 
Last edited by a moderator:

MeowFace

Meow
Veteran
Joined
Feb 22, 2015
Messages
1,034
Reaction score
184
First Language
Meowish
Primarily Uses
Yup, leaving that out for flexibility, so he/she can pair it with the "players" in the leader board comparing the old variables with the new ones in his/her own way. (Don't want to end up making the whole leader board for him/her with my sleepy head. lol! ;) )

Your way paired the array with a number might just work if he/she knows how to implement it. :)
 

burntable

Veteran
Veteran
Joined
Oct 16, 2013
Messages
63
Reaction score
9
First Language
German
The sorting MeowFace suggested, works perfectly fine. I can now compare the wins (if $game_variables[1] == $game_variables[6]) in a conditional branch and give everyone its rank. Sharing positions/ranks is no problem in my case.

To be honest Adiktuzmiko's way is too pro for me. I don't really know what to do with it. Haha!

Thank you both, your really helped me out!
 
Last edited by a moderator:

burntable

Veteran
Veteran
Joined
Oct 16, 2013
Messages
63
Reaction score
9
First Language
German
Does anyone know how to do this in MV?


I tried different ways, but couldn't figure out the correct JS syntax.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Don't forget, aspiring writers: Personality isn't what your characters do, it is WHY they do it.
Hello! I would like to know if there are any pluggings or any way to customize how battles look?
I was thinking that when you start the battle for it to appear the eyes of your characters and opponents sorta like Ace Attorney.
Sadly I don't know how that would be possible so I would be needing help! If you can help me in any way I would really apreciate it!
The biggest debate we need to complete on which is better, Waffles or Pancakes?
rux
How is it going? :D
Day 9 of giveaways! 8 prizes today :D

Forum statistics

Threads
106,050
Messages
1,018,548
Members
137,835
Latest member
yetisteven
Top