Discuss Scratch

MarioBros956
Scratcher
100+ posts

How to Optimize this Code?

Hi everyone, as shown in the image, this is a level system I coded that has a whole wall of code for each level, using if/elses to make it work. The level system works perfectly fine, but I don't think it needs to take 333 blocks to make it work. Simply put, how do I make this shorter and more optimized?


Edit: I put the wrong image file.

Last edited by MarioBros956 (Aug. 8, 2025 15:36:16)

michaeljackson1365
Scratcher
1000+ posts

How to Optimize this Code?

holy cow.. Luna Tuna Lunas
anyways much of this ultra long script seems repetitive, so try this:
forever
...
switch costume to (LVL)
if <touching (mouse pointer v)?> then
set size to ((size)+(((120)-(size))/(4)))
if <<mouse down?> and <<(COINS) = (coin removal?)> or <(COINS) > (coin removal?)>>> then
start sound (Level up v)
set size to ((size)+(((140)-(size))/(4)
change [COINS v] by ((coin removal?) * (-1)
change [LVL v] by (1)
end
else
set size to ((size)+(((100)-(size))/(4)
end

Last edited by michaeljackson1365 (Aug. 8, 2025 15:54:31)

MarioBros956
Scratcher
100+ posts

How to Optimize this Code?

michaeljackson1365 wrote:

holy cow.. Luna Tuna Lunas
anyways much of this ultra long script seems repetitive, so try this:
forever
...
switch costume to (LVL)
if <touching (mouse pointer v)?> then
set size to ((size)+(((120)-(size))/(4)))
if <<mouse down?> and <<(COINS) = (coin removal?)> or <(COINS) > (coin removal?)>>> then
start sound (Level up v)
set size to ((size)+(((140)-(size))/(4)
change [COINS v] by ((coin removal?) * (-1)
change [LVL v] by (1)
end
else
set size to ((size)+(((100)-(size))/(4)
end


What does coin removal stand for?
MarioBros956
Scratcher
100+ posts

How to Optimize this Code?

bump
michaeljackson1365
Scratcher
1000+ posts

How to Optimize this Code?

it's a variable, as i noticed the coins being removed per level (if you have that many coins or greater) only go up, however it doesn't seem to be linear. As for the coin removal variable:
if < not < ((costume # v) of (levels v)) = (LVL)>> then
if < (LVL) = (8) > then
change [coin removal? v] by (500)
end
end
alr, test this whole optimization ordeal i gave you

Last edited by michaeljackson1365 (Aug. 8, 2025 16:14:35)

MarioBros956
Scratcher
100+ posts

How to Optimize this Code?

michaeljackson1365 wrote:

it's a variable, as i noticed the coins being removed per level (if you have that many coins or greater) only go up, however it doesn't seem to be linear. As for the coin removal variable:
if < not < ((costume # v) of (levels v)) = (LVL)>> then
if < (LVL) = (8) > then
change [coin removal? v] by (500)
end
end
alr, test this whole optimization ordeal i gave you
Works perfectly! thank you!

Powered by DjangoBB