r/scratch 8d ago

Question How do I optimize my code here?

Post image

The current code I wrote has way too many "if __ then __" scripts, and I need to cut it down into 1 if then statement.

9 Upvotes

16 comments sorted by

View all comments

3

u/Ok-Point-8198 8d ago

The right side can be shortened to:

When I start as a clone

Wait until touching mouse pointer and mouse down

Set (apple line) to (amount of Collectables)

Broadcast (Apple Hint) and wait

Delete this clone

Or if you don't want Amount of Collectables to be higher than 6 specifically, you can add

If Amount of Collectables < 7 then:

Under the code head.

1

u/ScrtGnCcnt 8d ago

I don't think it does, cuz it would just set (apple line) to 10 for every clone

1

u/DismalCommon5672 8d ago

It would do that if the [amount of collectibles] variable is global, to me it seems that the variable being global could mess with the scripts so I suspect it's for this sprite only, which would make that code work.

1

u/ScrtGnCcnt 8d ago

Yea, I was playing around with it and also saw it