Discuss Scratch

Newt780
New Scratcher
3 posts

Sprite list

Hello i am new to scratch and am trying to build an interactive game. I an trying to build a block of code that includes a list of sprites that allows “Sprite#1” for example to play a sound or perform an action when it touches any of the sprites in the list. Below i will input what i do for 1 or 2
interactions but it can be brutal if there are for example 20 sprites i want “Sprite #1” to interact with in one way and 20 in another way. Any help will be greatly appreciated.

if <<touching [ Sprite # 2] ?> or < touching [ Sprite # 3] ?>> then
play sound [ Screem]
end


Thanks in advance.
Programming_Guru
Scratcher
84 posts

Sprite list

You can do that, but It would be kind of inefficient if timed poorly, what you could do would be:


w
when green flag clicked
forever

if <touching [(item ( (i)) of [ list]) v] ?> then
play sound [ Scream]

end
change [ i] by (1)

end

But if timed right the collision won't be noticed, You could also pass the name of a sprite to the sprite checking the collision like:


w
when green flag clicked
forever

if <[ List] contains [ (spriteTouching)]> then
play sound [ Scream]

end

end

Those are the only ways I could think of to do it. If you have any more questions please feel free to ask!
Newt780
New Scratcher
3 posts

Sprite list

Thank you for your help.

How would i go about adding the sprites themselves to the list? In order to implement the first loop you displayed. The second loop leads to an infinite loop of screams as it will always be true and isnt actually testing for the collision between 2 sprites at least based of what i understand, which at the moment is pretty limited.

I was hoping to find a block simply labeled “Sprite X” that i could add to either a list or a variable, many blocks identify the sprites in drop down menus but i cant seem to find a preset block that simply references the sprite as an object.
gor-dee
Scratcher
1000+ posts

Sprite list

Not exactly sure if this is what you want but to add sprites to a list you can broadcast
broadcast [add sprites to list]

then in the sprite s you want added to the list
when I receive [add sprites to list]
add [MyName] to [list]
Blue-Monkey
Scratcher
100+ posts

Sprite list

You can do this:

First, makes sure the list has all of the sprite names. Make the script below and click on it:
delete (all v) of [list v]
add [sprite1] to [list v]
add [sprite2] to [list v]
add [sprite1] to [list v]
...

Then, we need the collision detection:
when green flag clicked
forever
set [item v] to [0]
repeat (amount of sprites)
change [item v] by (1)
if <touching (item (item) of [list v]) ?> then
play sound [scream v]
...
end

end

end
Replace the amount of sprites variable with the amount of sprites. Hope this helped!
Newt780
New Scratcher
3 posts

Sprite list

Blue-Monkey wrote:

You can do this:

First, makes sure the list has all of the sprite names. Make the script below and click on it:
delete (all v) of [list v]
add [sprite1] to [list v]
add [sprite2] to [list v]
add [sprite1] to [list v]
...

Then, we need the collision detection:
when green flag clicked
forever
set [item v] to [0]
repeat (amount of sprites)
change [item v] by (1)
if <touching (item (item) of [list v]) ?> then
play sound [scream v]
...
end

end

end
Replace the amount of sprites variable with the amount of sprites. Hope this helped!


Thank you this works great!
PlasmaWolf12345
Scratcher
2 posts

Sprite list

play sound [ v] until done
play sound [ v] until done
play sound [ v] until done
play sound [ v] until done
play sound [ v] until done
play sound [ v] until done
play sound [ v] until done
play sound [ v] until done
play sound [ v] until done
play sound [ v] until done
-_Soul_-
Scratcher
100+ posts

Sprite list

PlasmaWolf12345 wrote:

play sound [ v] until done
play sound [ v] until done
play sound [ v] until done
play sound [ v] until done
play sound [ v] until done
play sound [ v] until done
play sound [ v] until done
play sound [ v] until done
play sound [ v] until done
play sound [ v] until done
..?
Amelia_Gastelum
Scratcher
15 posts

Sprite list

Not HELPING
Vihaans20
Scratcher
1 post

Sprite list

hello, seeing that you where discussing on the topic of adding sprites to lists, I am building a version of fruit ninja where every once in while a zombie comes along and turns all the other fruit in to zombies, so I have to make a list called “fruit” so if a sprite is identified as a “fruit”,it will turn into a zombie but I am not sure how to do that.

I need help.(so please help if you can)

Powered by DjangoBB