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

#1 2010-11-28 10:10:46

SeptimusHeap
Scratcher
Registered: 2010-02-01
Posts: 1000+

How to find the position of an item in a list...

Is there a quick way to find the position of an item in a said list?

Like if list [list] looked like this
a
a
a
a
a
a
a
a
b
a
a
a
a

And I wanted to find the position of b (9). How would I do this?


http://i46.tinypic.com/dw7zft.png

Offline

 

#2 2010-11-28 10:20:28

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Re: How to find the position of an item in a list...

This is the fastest way I think:
http://i56.tinypic.com/33b1dsm.gif
However, that's not very fast, so take the second script tidbit and copy it into the repeat block as many times as you want.  The more you copy it, the faster it will run.

For the variable block "set item to ()", make that what you're trying to find (in this case "b").

EDIT:  Er, I realize "set item to (a)" should read "set item to (b)".

Last edited by Kileymeister (2010-11-28 10:21:59)


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

#3 2010-11-28 10:34:06

SeptimusHeap
Scratcher
Registered: 2010-02-01
Posts: 1000+

Re: How to find the position of an item in a list...

Thanks! That's what I was thinking, and, it actually works faster then what I remember...


http://i46.tinypic.com/dw7zft.png

Offline

 

Board footer