Discuss Scratch

ScratchjrUP
Scratcher
15 posts

How do you check how many of one item are in a list.

Hi Fellow scratcher. I am trying to make a game based on plague inc and I have 300 clones each updating their clone # on a list telling if they are healthy infected or dead. I need a script that counts how many of one item are in a list and sets that number to a variable. I used this script but when I tried using it the variables it kept on saying 0.
link to image (sorry couldn't upload directly)
The Custom Block is set to run without screen refresh btw.
deck26
Scratcher
1000+ posts

How do you check how many of one item are in a list.

Have you checked your list contains what you expect before trying to count them? If the list is local (this sprite only) each clone will have its own copy.
MijiGamin1_is_cool
Scratcher
100+ posts

How do you check how many of one item are in a list.

You could prob do:

set [current list item v] to [1]
repeat (length of [list v] :: list)
if <(item (current list item) of [list v] :: list) = [thing]> then
change [number of things in list v] by (1)
end
change [current list item v] by (1)
end

Last edited by MijiGamin1_is_cool (Nov. 22, 2022 17:17:29)

ScratchjrUP
Scratcher
15 posts

How do you check how many of one item are in a list.

deck26 the list is for all sprites. I think the problem is that is run the screen refresh.
ScratchjrUP
Scratcher
15 posts

How do you check how many of one item are in a list.

MijiGamin1_is_cool yeah thanks for reminding that I need to set the variable at the beginning big oof on my part.
ScratchjrUP
Scratcher
15 posts

How do you check how many of one item are in a list.

MijiGamin1_is_cool wrote:

You could prob do:

set [current list item v] to [1]
repeat (length of [list v] :: list)
if <(item (current list item) of [list v] :: list) = [thing]> then
change [number of things in list v] by (1)
end
change [current list item v] by (1)
end

Powered by DjangoBB