This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-09-04 21:23:15

Validyk
New Scratcher
Registered: 2012-09-04
Posts: 2

How to make a list read in order and make sprite say the largest #

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

 

#2 2012-09-05 03:21:35

jontmy00
Scratcher
Registered: 2011-11-28
Posts: 1000+

Re: How to make a list read in order and make sprite say the largest #

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)


FOR ALL THE NEWS ON UPDATES FOR SIMPLISTICRAFT, CLICK HERE.

Offline

 

#3 2012-09-05 04:38:22

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: How to make a list read in order and make sprite say the largest #

^^ 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  smile

Good luck  smile


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#4 2012-09-05 04:45:41

jontmy00
Scratcher
Registered: 2011-11-28
Posts: 1000+

Re: How to make a list read in order and make sprite say the largest #

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?


FOR ALL THE NEWS ON UPDATES FOR SIMPLISTICRAFT, CLICK HERE.

Offline

 

#5 2012-09-05 06:04:31

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: How to make a list read in order and make sprite say the largest #

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) secs

Improved. 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.


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

Board footer