Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How can I sort items in my list?
- TheBiggesterHat
-
60 posts
How can I sort items in my list?
I have a game that pits different options against each other one by one. I wanted a quick way to simulate a round-robin kinda tourney so I made one. Unimportant. You pit whatever options against each other, whoever wins gets a point. test I ran made something like this.
Candidate score
(list number corresponding to the candidate)|(their score)
1 | 1
2 | 2
3 | 0
4 | 3
I want to then sort these into a different list that shows which candidate got what score.
Results
1 | d:3
2 | b:2
3 | a:1
4 | c:0
It's tough because I need it to be versatile. What if a and b both got 3 votes and c and d got 0, how do I deal with duplicate numbers? And how do I compensate for any amount of candidates? since this project is definitely built to take like a hundred of em. I just couldn't really figure anything out in my head so any idea would be rad
Candidate score
(list number corresponding to the candidate)|(their score)
1 | 1
2 | 2
3 | 0
4 | 3
I want to then sort these into a different list that shows which candidate got what score.
Results
1 | d:3
2 | b:2
3 | a:1
4 | c:0
It's tough because I need it to be versatile. What if a and b both got 3 votes and c and d got 0, how do I deal with duplicate numbers? And how do I compensate for any amount of candidates? since this project is definitely built to take like a hundred of em. I just couldn't really figure anything out in my head so any idea would be rad
- BlazingDan
-
100+ posts
How can I sort items in my list?
how many candidates are expected? is it in the tens? in the hundreds? the thousands? the hundreds of thousands? depending on the amount of candidates you would need a different algorithm. I have a game that pits different options against each other one by one. I wanted a quick way to simulate a round-robin kinda tourney so I made one. Unimportant. You pit whatever options against each other, whoever wins gets a point. test I ran made something like this.
Candidate score
(list number corresponding to the candidate)|(their score)
1 | 1
2 | 2
3 | 0
4 | 3
I want to then sort these into a different list that shows which candidate got what score.
Results
1 | d:3
2 | b:2
3 | a:1
4 | c:0
It's tough because I need it to be versatile. What if a and b both got 3 votes and c and d got 0, how do I deal with duplicate numbers? And how do I compensate for any amount of candidates? since this project is definitely built to take like a hundred of em. I just couldn't really figure anything out in my head so any idea would be rad
- TheBiggesterHat
-
60 posts
How can I sort items in my list?
However many you could fit on a list(200,000) but honestly I wouldn't see anyone going up to 1000
- deck26
-
1000+ posts
How can I sort items in my list?
There's no standard way to handle positions where people get the same score and it depends a bit on what you're going to do with the data. If you just present it as per your list a tied position is not always obvious.
One more obvious option might be to show the score and all users who got that score as a single list item - eg item 2: 3 : A : C meaning A and C both scored 3 points. That's reasonably easy to do if all scores are whole numbers - start with 0 and increase in the loop until you've dealt with all the scores. Higher scores are inserted at position 1 of the list as they are needed.
Once you have the list of users you know how many entries there are. Getting the output above is easy but the list item number doesn't necessarily correspond to the position - eg if 2 people get the top score and two get the next highest score the latter two are in equal third place so it might be confusing if the list shows them in 2nd place. An easy fix for that is to add an empty line for each duplicate getting a score. So
1: 6 : A : B A and B are first equal with 6 points
2: empty list item, no one is second
3: 2 : C : D C and D are third equal with 2 points
4: no one was fourth
One more obvious option might be to show the score and all users who got that score as a single list item - eg item 2: 3 : A : C meaning A and C both scored 3 points. That's reasonably easy to do if all scores are whole numbers - start with 0 and increase in the loop until you've dealt with all the scores. Higher scores are inserted at position 1 of the list as they are needed.
Once you have the list of users you know how many entries there are. Getting the output above is easy but the list item number doesn't necessarily correspond to the position - eg if 2 people get the top score and two get the next highest score the latter two are in equal third place so it might be confusing if the list shows them in 2nd place. An easy fix for that is to add an empty line for each duplicate getting a score. So
1: 6 : A : B A and B are first equal with 6 points
2: empty list item, no one is second
3: 2 : C : D C and D are third equal with 2 points
4: no one was fourth
- PaSc_Clan
-
64 posts
How can I sort items in my list?
Just for clarification, you're trying to make a table system?
- PaSc_Clan
-
64 posts
How can I sort items in my list?
If this is the case, the following code may be able to help you out. Just for clarification, you're trying to make a table system?
(Table Index) // Repeat Index
(Item) // What the item is
(Items :: list) // Where the items will be stored
(Table :: list) // Where the items are
define Decode Table (item#) // Run without screen refresh
delete all of [Items v]
set [Table Index v] to [0]
set [Item v] to []
repeat (length of (item (item#) of [Table v]))
change [Table Index v] by [1]
if <(letter (Table Index) of (item (item#) of [Table v])) = [,]> then
add (Item) to [Items v]
set [Item v] to []
else
set [Item v] to (join (Item) (letter (Table Index) of (item (item#) of [Table v])))
end
end
add (Item) to [Items v]
Your table should consist of lists.
1:a,b,c,d…
2:a,b,c,d…
etc
Since you're trying to make a scoring system, you should use number Indexes and to change the score use this system. If you want your divider to do something other than “,” then you can change it to something like “|”
Last edited by PaSc_Clan (Feb. 19, 2025 17:11:27)
- Discussion Forums
- » Help with Scripts
-
» How can I sort items in my list?