Discuss Scratch

exmster
Scratcher
20 posts

Variable Change

Hey! I'm trying to make it so then when my points variable reaches 10, another variable changes to 1. How can I do this? Thank you!
Catscratcher07
Scratcher
1000+ posts

Variable Change

forever
if <(var) = [10]> then
change [var2 v] by (1)
end
end
you can also use greater than

trouble with clones? view my clone id toolbox! I also have built the bases of a tower defense game link here.
If someone on help with scripts is saying that something can't be done, they should be suspected of being a team limit grunt.
Wanna be the very best? Here's your chance!
exmster
Scratcher
20 posts

Variable Change

I tried this but it automatically increased to 30-40. How do you fix this?
Jlerpy
Scratcher
1000+ posts

Variable Change

The trouble there is that as long as the first variable is 10, the 2nd will keep rocketing up, rather than just once.
The only way I can think to make it only happen once each time would be to make a third variable that it checks the first variable is higher than, does the +1 to the 2nd variable, then increases the 3rd variable.
deck26
Scratcher
1000+ posts

Variable Change

Use wait until var=10 rather than a forever/if combination.

wait until <(var) > [9]>
change [var2 v] by [1]

I've gone for > 9 rather than = 10 because if score can increase by more than 1 between checks you might miss the event since the value is 10 for too short a time. Whether that is an issue depends on how the variable changes but it demonstrates an alternative.
HeHeTeeHeeHee
Scratcher
100+ posts

Variable Change

exmster wrote:

I tried this but it automatically increased to 30-40. How do you fix this?

Oh, maybe try stopping the script afterward because once the variable is equal to 10, it will always fire the if since it is in a forever loop. You need the forever loop so that it will continually check to see so…

The one problem with this is that you need to find a way to start the script again (if you want it to run again), so I reccomend using a broadcast.

when I receive [StartScript v]
forever
if <[var v] = [10]> then

set [var2 v] to [1] // Set/change this to whatever you want
stop [this script v]
end
end

Last edited by HeHeTeeHeeHee (March 17, 2022 12:27:29)


HeHeTeeHeeHee wrote:

i'm brain dead aren't i
i usually use advanced topics or help with scripts but sometimes i can be found in things i'm playing and reading

Powered by DjangoBB