Pages: 1
I am doing a project for class and i am a bit confused.
I need the sprite to say the largest number on the list i created, i am not sure of how to do that. I also need to order the numbers i posted in order from least to greatest.
please help/advice
Offline
Here:
when gf clicked set [largest v] to [0] set [counter v] to [0] repeat <length of [list v]> change [counter v] by (1) if <(item (counter) of [list v]) > (largest)> set [largest v] to (item (counter) of [list v]) end end say (largest) for (whatever) secs
Last edited by jontmy00 (2012-09-05 03:22:00)
Offline
^^ That is good for finding the largest but it won't put the others in order from smallest to largest. I can't give you the code right now but you may wish to take a look at this to help you (it orders numbers from largest to smallest but aslo includes words) - but should still be helpful
Good luck
"Offline
jontmy00 wrote:
Here:
when gf clicked set [largest v] to [0] set [counter v] to [0] repeat <length of [list v]> repeat <length of [list v]> change [counter v] by (1) if <(item (counter) of [list v]) > (largest)> set [largest v] to (item (counter) of [list v]) end end add (largest) to [sort v] delete (counter) of [list v] set [largest v] to [0] set [counter v] to [0] end say (item (1 v) of [sort v]) for (2) secs
Improved. How's this now?
Offline
jontmy00 wrote:
jontmy00 wrote:
Here:
when gf clicked set [largest v] to [0] set [counter v] to [0] repeat <length of [list v]> repeat <length of [list v]> change [counter v] by (1) if <(item (counter) of [list v]) > (largest)> set [largest v] to (item (counter) of [list v]) end end add (largest) to [sort v] delete (counter) of [list v] set [largest v] to [0] set [counter v] to [0] end say (item (1 v) of [sort v]) for (2) secsImproved. How's this now?
That won't work, because counter will always be the last index on the list.
when gf clicked set [passes v] to [0] repeat (length of [list v] ) set [index v] to (passes) // Set to 0 of you want it sorted small to large set [largest v] to [0] set [largest index v] to [0] repeat ((length of [list v] ) - (passes)) change [index v] by (1) if <(largest) < (item (index) of [list v] )> set [largest v] to (item (index) of [list v] ) set [largest index v] to (index) end end delete (largest index) of [list v] insert (largest) at (1 v) of [list v] //add (largest) to [list v] if you want to sort small to large change [passes v] by (1) end set [largest v] to (item (1 v) of [list v] ) // Do (item (last v) of [list v] if sorted small to large
That will sort from largest to smallest.
Offline
Pages: 1