Discuss Scratch

purplepancake01
Scratcher
10 posts

When variable changes

I'd say semi, b/c I understand that you don't want to make a whole script for it, BUT, you can use a custom block for it.

forever
set (foo) to [something]
if <not <(foo) = [something]>> then (do something)

Last edited by purplepancake01 (June 25, 2022 22:46:32)

carteradams123
Scratcher
49 posts

When variable changes

Late to the party, but full support. I'm creating a game where a “forever” loop cannot work in place of a “when variable changed?”

The specific scenario is to update a stamp when a certain variable changes. Other stamps need to be placed over it later, so using a forever loop to repeatedly update the bottom stamp cannot work as it would overwrite the other stamp layers. This creates a need to update the stamp only when necessary, which is each variable update.
imfh
Scratcher
1000+ posts

When variable changes

carteradams123 wrote:

Late to the party, but full support. I'm creating a game where a “forever” loop cannot work in place of a “when variable changed?”

The specific scenario is to update a stamp when a certain variable changes. Other stamps need to be placed over it later, so using a forever loop to repeatedly update the bottom stamp cannot work as it would overwrite the other stamp layers. This creates a need to update the stamp only when necessary, which is each variable update.
Try using a second variable to keep track of the old value.

forever
if <not <(variable)= (old variable)>> then
set [old variable v] to (variable)
stamp
end
end

Even better, send a broadcast whenever you change the variable. You could even make a custom block to update that specific variable.
FishTC
Scratcher
26 posts

When variable changes

CatsUnited wrote:

No support, easy workaround…

forever

if <doing something :: sensing> then

change [score v] by (1)
... :: grey
end

end
I tried this, but didn't really find a sense button that detects variable changes.
-Valtren-
Scratcher
1000+ posts

When variable changes

FishTC wrote:

CatsUnited wrote:

No support, easy workaround…

forever

if <doing something :: sensing> then

change [score v] by (1)
... :: grey
end

end
I tried this, but didn't really find a sense button that detects variable changes.
One alternative could be making it so that whenever a variable is changed it updates something. A bit manual but if you're in control of when a variable changes then it should be good.
Another workaround could be this:
define detect
set [oldvar v] to (my variable)
wait until <not <(oldvar) = (my variable)>>
it's not perfect but it would detect if the variable changed.
ajskateboarder
Scratcher
1000+ posts

When variable changes

Bump from duplicate
lfg30700
Scratcher
1000+ posts

When variable changes

Bump!
acohen_bhusd
Scratcher
500+ posts

When variable changes

the other topic with more posts was closed as it was a duplicate, post count does not matter
acohen_bhusd
Scratcher
500+ posts

When variable changes

bump
Randomeder
Scratcher
2 posts

When variable changes

wait what discussion pages are still up?? its been a few years since I have been on scratch
acohen_bhusd
Scratcher
500+ posts

When variable changes

bump
tagrim123
Scratcher
500+ posts

When variable changes

when [timer v] > ((timer) - <not<(old) = (targetvariable)>>)
set [old v] to (var)
... // Do Something
Until this is added, use this! BUMP
Support!

Powered by DjangoBB