Here's my problem: I have a list where I want it to automatically sort a group of data in ascending order, so that the biggest amount is at the bottom.
This is what one piece of data looks like:
[ABC 1:34]
I want the time to be sorted, but not the name (ABC) so that the fastest time is first. Does anyone know how to order lists in this way? Thanks for any help you can give me.
Last edited by Thenuclearduck (2011-09-24 16:50:12)
Offline
Thenuclearduck wrote:
Here's my problem: I have a list where I want it to automatically sort a group of data in ascending order, so that the biggest amount is at the bottom.
This is what one piece of data looks like:
[ABC 1:34]
I want the time to be sorted, but not the name (ABC) so that the fastest time is first. Does anyone know how to order lists in this way? Thanks for any help you can give me.![]()
It would be easiest to store the names and times in seperate lists, so you don't have to parse it. It would be also easier to just list it in seconds (i.e. 1:34 = 94) and convert it later.

Offline
Greenatic wrote:
Thenuclearduck wrote:
Here's my problem: I have a list where I want it to automatically sort a group of data in ascending order, so that the biggest amount is at the bottom.
This is what one piece of data looks like:
[ABC 1:34]
I want the time to be sorted, but not the name (ABC) so that the fastest time is first. Does anyone know how to order lists in this way? Thanks for any help you can give me.![]()
It would be easiest to store the names and times in seperate lists, so you don't have to parse it. It would be also easier to just list it in seconds (i.e. 1:34 = 94) and convert it later.
I understand, but is there any way to order it in the form it is in now?
Offline
Thenuclearduck wrote:
Greenatic wrote:
Thenuclearduck wrote:
Here's my problem: I have a list where I want it to automatically sort a group of data in ascending order, so that the biggest amount is at the bottom.
This is what one piece of data looks like:
[ABC 1:34]
I want the time to be sorted, but not the name (ABC) so that the fastest time is first. Does anyone know how to order lists in this way? Thanks for any help you can give me.![]()
It would be easiest to store the names and times in seperate lists, so you don't have to parse it. It would be also easier to just list it in seconds (i.e. 1:34 = 94) and convert it later.
I understand, but is there any way to order it in the form it is in now?
Well, yes. But it will be painfully difficult, because you have to parse it.

Offline
Greenatic wrote:
Thenuclearduck wrote:
Greenatic wrote:
It would be easiest to store the names and times in seperate lists, so you don't have to parse it. It would be also easier to just list it in seconds (i.e. 1:34 = 94) and convert it later.I understand, but is there any way to order it in the form it is in now?
Well, yes. But it will be painfully difficult, because you have to parse it.
Could you tell me how? (If you know.) If you don't know just tell me how to do it with all the stuff you sggested.
Offline
Thenuclearduck wrote:
Greenatic wrote:
Thenuclearduck wrote:
I understand, but is there any way to order it in the form it is in now?
Well, yes. But it will be painfully difficult, because you have to parse it.
Could you tell me how? (If you know.) If you don't know just tell me how to do it with all the stuff you sggested.
Well, I'm not sure about the parser. So to convert your M:S times to S, just use (M * 60) + S. (And, just so you know, I meant to put two identical repeat loops in this code).
set counter to 1.
repeat (length of times) {
repeat (length of times) {
if <not <(counter) = (length of times)>> {
if <(item (counter) of times) > (item ((counter) + 1) of times)> {
set sorter to (item (counter) of times).
replace item (counter) of times with (item ((counter) + 1) of times).
replace item ((counter) + 1) of times with (sorter).
}
}
change sorter by 1.
}
set counter to 1.
}
Last edited by Greenatic (2011-09-24 18:04:02)

Offline
Greenatic wrote:
Thenuclearduck wrote:
Greenatic wrote:
Well, yes. But it will be painfully difficult, because you have to parse it.Could you tell me how? (If you know.) If you don't know just tell me how to do it with all the stuff you sggested.
Well, I'm not sure about the parser. So to convert your M:S times to S, just use (M * 60) + S. (And, just so you know, I meant to put two identical repeat loops in this code).
set counter to 1.
repeat (length of times) {
repeat (length of times) {
if <not <(counter) = (length of times)>> {
if <(item (counter) of times) > (item ((counter) + 1) of times)> {
set sorter to (item (counter) of times).
replace item (counter) of times with (item ((counter) + 1) of times).
replace item ((counter) + 1) of times with (sorter).
}
}
change sorter by 1.
}
set counter to 1.
}
In that case, how can I get the name to stay with the number when the numbers are sorted?
Offline
Thenuclearduck wrote:
Greenatic wrote:
Thenuclearduck wrote:
Could you tell me how? (If you know.) If you don't know just tell me how to do it with all the stuff you sggested.
Well, I'm not sure about the parser. So to convert your M:S times to S, just use (M * 60) + S. (And, just so you know, I meant to put two identical repeat loops in this code).
set counter to 1.
repeat (length of times) {
repeat (length of times) {
if <not <(counter) = (length of times)>> {
if <(item (counter) of times) > (item ((counter) + 1) of times)> {
set sorter to (item (counter) of times).
replace item (counter) of times with (item ((counter) + 1) of times).
replace item ((counter) + 1) of times with (sorter).
}
}
change sorter by 1.
}
set counter to 1.
}In that case, how can I get the name to stay with the number when the numbers are sorted?
Sorry it took me so long to reply.
Create another variable, "nsorter". Replace the previous code with this:
set counter to 1.
repeat (length of times) {
repeat (length of times) {
if <not <(counter) = (length of times)>> {
if <(item (counter) of times) > (item ((counter) + 1) of times)> {
set sorter to (item (counter) of times).
set nsorter to (item (counter) of names).
replace item (counter) of times with (item ((counter) + 1) of times).
replace item ((counter) + 1) of times with (sorter).
replace item (counter) of names with (item ((counter) + 1) of names).
replace item ((counter) + 1) of names with (nsorter).
}
}
change sorter by 1.
}
set counter to 1.
}
Last edited by Greenatic (2011-09-24 21:12:27)

Offline
Thank you very much this works perfectly now I can have a leaderboard. I will give you plenty of credit in the project notes!
Offline
I've just noticed how the sorter only seems to be ble to sort 3 entries. Do you know why?
Offline
Thenuclearduck wrote:
I've just noticed how the sorter only seems to be ble to sort 3 entries. Do you know why?
Is "times" only 3 entries long? Let me test it for a second, maybe I typed something wrong...
EDIT: Yeah, I typed some things wrong. New code:
set counter to 1.
repeat (length of times) {
repeat (length of times) {
if <not <(counter) = 1>> {
if <(item (counter) of times) < (item ((counter) - 1) of times)> {
set sorter to (item (counter) of times).
set nsorter to (item (counter) of names).
replace item (counter) of times with (item ((counter) - 1) of times).
replace item ((counter) - 1) of times with (sorter).
replace item (counter) of names with (item ((counter) - 1) of names).
replace item ((counter) - 1) of names with (nsorter).
}
}
change counter by 1.
}
set counter to 1.
}
Sorry for the error last time. This should work.
Last edited by Greenatic (2011-09-25 13:18:47)

Offline
Hey, the game I was gonna do with this is now done, so here it is. http://scratch.mit.edu/projects/Thenuclearduck/2046581
Offline
Just so you know, this should probably have been in All About Scratch, not Advanced Topics. It is a common misconception that Advanced Topics are for more advanced code for Scratch projects, but it is actually for programming that goes beyond Scratch (e.g. Squeak, HTML, C++, etc.)
Offline
MoreGamesNow wrote:
Just so you know, this should probably have been in All About Scratch, not Advanced Topics. It is a common misconception that Advanced Topics are for more advanced code for Scratch projects, but it is actually for programming that goes beyond Scratch (e.g. Squeak, HTML, C++, etc.)
Welcome to the Advanced Topics wrote:
• Advanced Scratch Programming
Yes, the ATs are also a place to share advanced Scratch programming. Scratch programs that use complex algorithms, or are breakthroughs in Scratch (ie a recursive engine, a chess engine, or a programming language within Scratch), deserve to be shared and discussed here. Sometimes, people integrate Scratch with other languages (The coolest example I can think of would be connecting it to AppleScript, to read the Gyroscopic sensor values of a MacBook Pro, for a balance game), connect it to the real world in cool ways (People have used Bluetooth to use a Wii remote or Kinect to control Scratch), or connect Scratch programs via Mesh (I've seen many chat programs). The idea is not to advertise, but to develop.
SEE HERE
**cough*ignorance*cough*
Last edited by Greatdane (2011-11-04 20:53:42)
Offline
Scratch Website wrote:
Advanced Topics: "Talk about technical aspects or advanced features."
All About Scratch: "Questions about Scratch? No question is too basic! "
This may simply be my opinion, but it seems to me that any questions about using Scratch to make projects belongs in "questions about scratch", not "technical aspects or advanced features", as using blocks to make projects are what Scratch is all about and therefore - in my opinion - do not fall under "advanced features".
And your quote above talks about sharing advanced projects, not asking for help with them.
I guess when two people get their information from two different sources, their resulting opinions are bound to differ.
Last edited by MoreGamesNow (2011-11-04 22:44:24)
Offline
MoreGamesNow wrote:
Scratch Website wrote:
Advanced Topics: "Talk about technical aspects or advanced features."
All About Scratch: "Questions about Scratch? No question is too basic! "This may simply be my opinion, but it seems to me that any questions about using Scratch to make projects belongs in "questions about scratch", not "technical aspects or advanced features", as using blocks to make projects are what Scratch is all about and therefore - in my opinion - do not fall under "advanced features".
And your quote above talks about sharing advanced projects, not asking for help with them.
I guess when two people get their information from two different sources, their resulting opinions are bound to differ.
No question is too basic!
Technical aspects or advanced features.
Which one sounds more fitting to a quite advanced question that appears to have never been solved before on the forums?
Offline
I (writer of the quote above
) think this particular question is likely to fit in All About Scratch, because it is normal, though complex code. Advanced projects usually involve hard math or complex techniques, not complex code. You could put together a hundred blocks that just make a sprite move in a special way, or you could create a mathematical equation to cater to that motion. The latter is more advanced as it is "non-conventional" in a way.
It's hard to explain...
Offline
Hardmath123 wrote:
I (writer of the quote above
) think this particular question is likely to fit in All About Scratch, because it is normal, though complex code. Advanced projects usually involve hard math or complex techniques, not complex code. You could put together a hundred blocks that just make a sprite move in a special way, or you could create a mathematical equation to cater to that motion. The latter is more advanced as it is "non-conventional" in a way.
It's hard to explain...![]()
*shrugs* I don't really get all the fuss about moving forums. Unless you put sommething that has absolutely nothing to do with a forum in it, you get the question answered, don't you? Why does it matter which of two similar forums is it in?
Offline