Discuss Scratch

MsBoutell
Scratcher
3 posts

Change size by issue

I'm working on a simple sticky ball game lesson for students (basically Katamari) - the one issue that I'm having is that I'd like the ball sprite to grow by 10% each time it picks up a new sprite object. For some reason, it's not working the way I would hope.

Here's the code segment that isn't working:
For each sprite that it encounters -
if <touching [<touching [ thingy] ] ?> then
change size by (10)
end

Link to project: https://scratch.mit.edu/projects/557387849

Any advice?

Last edited by MsBoutell (Aug. 1, 2021 17:44:56)

The_Imaginarium
Scratcher
1000+ posts

Change size by issue

Your code isn't working because the conditionals are not within the forever loop. In theory, it looks like this would work, but since the computer will run all the specified actions in order, that's where it goes wrong.

When the green flag is pressed, the computer will check all the booleans and will return false to each of them, because when the ball begins, it is not touching any of the objects.

To fix this, simply place all the if statements within the forever loop.
awesome-llama
Scratcher
1000+ posts

Change size by issue

The if blocks to change the size only run once, when the green flag is clicked. Since they aren't part of the loop, they will not run at any other time.

Something basic like this would work.
when green flag clicked
wait until <touching [object v] ?>
change size by (10)


MsBoutell
Scratcher
3 posts

Change size by issue

This works! Thank you.

awesome-llama wrote:

The if blocks to change the size only run once, when the green flag is clicked. Since they aren't part of the loop, they will not run at any other time.

Something basic like this would work.
when green flag clicked
wait until <touching [object v] ?>
change size by (10)
MsBoutell
Scratcher
3 posts

Change size by issue

This doesn't work, because it makes the ball grow forever and not just once when it first encounters the object. The wait untl code in the post above does work, though. Thanks for your response.

The_Imaginarium wrote:

Your code isn't working because the conditionals are not within the forever loop. In theory, it looks like this would work, but since the computer will run all the specified actions in order, that's where it goes wrong.

When the green flag is pressed, the computer will check all the booleans and will return false to each of them, because when the ball begins, it is not touching any of the objects.

To fix this, simply place all the if statements within the forever loop.
PenguinLover1123
Scratcher
1000+ posts

Change size by issue

MsBoutell wrote:

I'm working on a simple sticky ball game lesson for students (basically Katamari) - the one issue that I'm having is that I'd like the ball sprite to grow by 10% each time it picks up a new sprite object. For some reason, it's not working the way I would hope.

Here's the code segment that isn't working:
For each sprite that it encounters -
if <touching [<touching [ thingy] ] ?> then
change size by (10)
end

Link to project: https://scratch.mit.edu/projects/557387849

Any advice?
Use this:

Good morning/afternoon/night

Powered by DjangoBB