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

#1 2013-04-12 18:27:39

dusty22
Scratcher
Registered: 2012-09-28
Posts: 49

Figuring out which item of a list?

So I have sprites checking to see if they're touching any of the other sprites on a list of those sprites. That works fine, but I can only check if I'm touching ANY of those list items,   I can't tell which item it is once I know it's touching any of those items.

Is it possible to do this in the same script that checks the whole list, or no?

Offline

 

#2 2013-04-13 03:44:02

shadowmouse
New Scratcher
Registered: 2013-02-03
Posts: 100+

Re: Figuring out which item of a list?

Yes it is. First so you know, any means a random one. Use a variable called listscanner which is initially set to 0. Have something like:

set [listscanner v] to (0)
repeat until <(listscanner) = (length of list [list v])>
change [listscanner v] by (1)
if <touching (item (listscanner) of [list v])>
set listscanner to (length of [list v])
other scipt
end
end

Offline

 

#3 2013-04-13 08:11:14

dusty22
Scratcher
Registered: 2012-09-28
Posts: 49

Re: Figuring out which item of a list?

Sweet!, thank you, Imma try this out!

Offline

 

#4 2013-04-13 08:38:30

sodaLA
New Scratcher
Registered: 2013-04-12
Posts: 8

Re: Figuring out which item of a list?

shadowmouse wrote:

Yes it is. First so you know, any means a random one. Use a variable called listscanner which is initially set to 0. Have something like:

set [listscanner v] to [0]
repeat until <(listscanner) = (length of (list v)>
change [listscanner v] by [1]
if <touching (item (listscanner) of [list v])?>
set [listscanner v] to (length of [list v])
other scipt
end
end

scratchblocks fixed.

Offline

 

#5 2013-04-13 08:41:36

sodaLA
New Scratcher
Registered: 2013-04-12
Posts: 8

Re: Figuring out which item of a list?

sodaLA wrote:

shadowmouse wrote:

Yes it is. First so you know, any means a random one. Use a variable called listscanner which is initially set to 0. Have something like:

set [listscanner v] to [0]
repeat until <(listscanner) = (length of (list v))>
change [listscanner v] by [1]
if <touching (item (listscanner) of [list v])?>
set [listscanner v] to (length of [list v])
other scipt
end
end

scratchblocks fixed.

now they're fixed.  wink

Offline

 

#6 2013-04-13 08:45:06

sodaLA
New Scratcher
Registered: 2013-04-12
Posts: 8

Re: Figuring out which item of a list?

sodaLA wrote:

sodaLA wrote:

shadowmouse wrote:

Yes it is. First so you know, any means a random one. Use a variable called listscanner which is initially set to 0. Have something like:

set [listscanner v] to [0]
repeat until <(listscanner) = [length of (list v)]>
change [listscanner v] by [1]
if <touching (item (listscanner) of [list v])?>
set [listscanner v] to (length of [list v])
other scipt
end
end

scratchblocks fixed.

now they're fixed.  wink

now they are

Offline

 

Board footer