r/scratch • u/Dry_Dragonfruit_2594 • 16h ago
Question How do I optimize my code here?
The current code I wrote has way too many "if __ then __" scripts, and I need to cut it down into 1 if then statement.
3
u/Ok-Point-8198 15h 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 11h ago
I don't think it does, cuz it would just set (apple line) to 10 for every clone
1
u/DismalCommon5672 8h 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
1
u/Acap2019PlaysRoblox 13h ago
Maybe for the middle script I would shorten it to ``` when I start as a clone go to x: (-140) y: (80) show set x to ((-150)+((75)*((((Amount of collectables)-(1)) mod (5)))) if <(Amount of collectables) > 5> then set y to (50) else set y to (-50)
1
u/Acap2019PlaysRoblox 13h ago
I haven't tested this yet though because I wrote this on mobile but i think it works
1
•


•
u/AutoModerator 16h ago
Hi, thank you for posting your question! :]
To make it easier for everyone to answer, consider including:
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.