Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » I need a simple way to detect variable change!
- 1kbrother
-
44 posts
I need a simple way to detect variable change!
I am making a script that uses a variable as the pen size
Thanks for your help!
and I want it to clear every time the variable/pen size changes. I don't want to have to make anymore variables, and I can't find a way to do it without making another variable.
Thanks for your help!
- Th3_C0d3r
-
100+ posts
I need a simple way to detect variable change!
Unfortunately your going to need 1 more variable with my script…
So here it is
Fairly simple script. Hope you find it useful.
-Scratch On!
So here it is
Fairly simple script. Hope you find it useful.

-Scratch On!
- 1kbrother
-
44 posts
I need a simple way to detect variable change!
Unfortunately your going to need 1 more variable with my script…
So here it is
Fairly simple script. Hope you find it useful.
-Scratch On!
I came up with a fairly similar script but I need a way to have it use only one variable, but thanks anyway!
- Th3_C0d3r
-
100+ posts
I need a simple way to detect variable change!
Could you please explain why you can't make another variable? Because the only way to detect a change is to compare it to something else. If you can't use a variable, perhaps you can use a List. I came up with a fairly similar script but I need a way to have it use only one variable, but thanks anyway!
-Scratch On!
- 1kbrother
-
44 posts
I need a simple way to detect variable change!
Could you please explain why you can't make another variable? Because the only way to detect a change is to compare it to something else. If you can't use a variable, perhaps you can use a List. I came up with a fairly similar script but I need a way to have it use only one variable, but thanks anyway!
-Scratch On!
I want to make my program as compact as possible and I want to try to limit the variables as much as possible.
- asivi
-
1000+ posts
I need a simple way to detect variable change!
You don't need another variable acting as a monitor.
Where are you changing such variable? put your block for clear there.
Where are you changing such variable? put your block for clear there.
- TheLogFather
-
1000+ posts
I need a simple way to detect variable change!
Yes – though it did occur to me that maybe 1kbrother has the Y1 variable showing as a slider that the user can change (and changing that changes the pen size). In that case the simplest solution really is to use another variable in a polling loop, as Th3_C0d3r said. You don't need another variable acting as a monitor.
Where are you changing such variable? put your block for clear there.
If you're not using any sounds in your project then, it's a bit weird, but you *could* use the “volume” for the comparison (maybe compare and set the volume set to a quarter of Y1, so you can get up to pen size of 255, if necessary).
Otherwise, if you *really* want to avoid seeing that extra variable appear in the Data palette, then you can use a trick with a clone which creates and uses the temporary variable when the clone gets created (but you delete the var from the original sprite so that it doesn't appear there).
Last edited by TheLogFather (Feb. 4, 2017 00:48:56)
- asivi
-
1000+ posts
I need a simple way to detect variable change!
If as @TheLogFather said you are changing the pen size with a variable slider and your pen is not visible you can use the direction reporter to detect it.
Last edited by asivi (Feb. 4, 2017 01:37:36)
- Howerd1
-
5 posts
I need a simple way to detect variable change!
Just store the previous value!
- duckboycool
-
1000+ posts
I need a simple way to detect variable change!
Adding one measly variable to the project will barely change your space at all. The script you would make would be larger itself, so with whatever you need it to be compact for, this will work fine.
(I mean Th3_c0d3r's one BTW)
(I mean Th3_c0d3r's one BTW)
Last edited by duckboycool (Feb. 4, 2017 05:24:19)
- 1kbrother
-
44 posts
I need a simple way to detect variable change!
Adding one measly variable to the project will barely change your space at all. The script you would make would be larger itself, so with whatever you need it to be compact for, this will work fine.
(I mean Th3_c0d3r's one BTW)
The reason I only want one variable is because I have to repeat this script all over my program, and I don't want to have to create an extra variable for no reason.
Anyways I found a way so thanks anyway.
- asivi
-
1000+ posts
I need a simple way to detect variable change!
If you are going to have a large bunch of variables a list could be useful.
- MasterDiamondMan
-
13 posts
I need a simple way to detect variable change!
I just can't find a way…
Maybe this?
I haven't checked…
Maybe this?
I haven't checked…
Last edited by MasterDiamondMan (March 7, 2020 16:13:52)
- Maarten_
-
100+ posts
I need a simple way to detect variable change!
Unfortunately your going to need 1 more variable with my script…
So here it is
Fairly simple script. Hope you find it useful.
-Scratch On!
IMHO using if blocks inside a repeat to *wait* for a change is dumb.
Not that it should not be used, but it's inefficient.
Please take a moment to consider using this way instead:
- LuvGoats_5
-
13 posts
I need a simple way to detect variable change!
I'm not sure if this is necroposting, but I found a simple way to detect a variable change that is a little easier to understand.


- LuvGoats_5
-
13 posts
I need a simple way to detect variable change!
Sorry, the YOUR VARIABLE parts were supposed to be the variables!!
- deck26
-
1000+ posts
I need a simple way to detect variable change!
That is no different - you're saving the value so you can compare the variable to the value it had. BUT you're setting the copy of the variable immediately before you check it so it is highly unlikely to have changed before the if block. I'm not sure if this is necroposting, but I found a simple way to detect a variable change that is a little easier to understand.
Not worth necroposting for!
- cavemanster
-
100+ posts
I need a simple way to detect variable change!
Last edited by cavemanster (Aug. 22, 2020 15:36:43)
- aarizkamran
-
100+ posts
I need a simple way to detect variable change!
what is your default value
- LuvGoats_5
-
13 posts
I need a simple way to detect variable change!
I'm sorry, I tested it. Waiting only 0.000000001 seconds makes no difference. If you made it longer, as in 1 second, it would have time to broadcast the following more than once. Broadcasting is almost instant, but takes some time. By making it 0.00000000001 seconds, it only gives the variable time to broadcast once. It works, do not tell me I'm wrong about this please. It makes sense, and any way you want to change it, go ahead.
- Discussion Forums
- » Help with Scripts
-
» I need a simple way to detect variable change!