I'm listening to global variable sensor-update messages using Remote Sensor Connections and I've come across a "feature" that is causing me problems.
Scratch is "remembering" the last value of a variable message sent and if the variable hasn't changed from one run to the next, then it does not issue a sensor-update when it encounters it in a script on the next run e.g
when gf clicked set test to 1
sensor -update "test" 1
message if test's value does not change anywhere else in the script.
Since I'm controlling hardware based on variable values, I need to reset my hardware to a fixed state using the value of my variables and I think it would be a lot better is Scratch always sent a sensor-update message when it encounters a set variable or change variable block.
Has anyone else come across this behaviour - would my request for a change to the sensor-update algorithm cause any problems with any else's programs?
regards
Simon
Last edited by SimpleScratch (2012-08-27 13:40:12)
Offline
Ah yes, I found this out when I was writing a script to only update the variable when it actually changes. Then I found out I didn't need to do that, it was already done for me.
I would suggest using broadcasts instead, since the same broadcast can be sent repeatedly without Scratch thinking "oh, I've already sent this, ignoring". But you do loose some speed when using broadcasts instead of variables.
Something you could do, is just add a zero before each variable update so like: sensor-update "test" 01, sensor-update "test" 001, etc. I don't know if it works, but it's a possibility. You could also do something like: sensor-update "test" "1 ignore everything after the first space" and just have the program ignore any extra data except for the first integer.
Hopefully that helps.
Offline
I would suggest using broadcasts instead, since the same broadcast can be sent repeatedly without Scratch thinking "oh, I've already sent this, ignoring".
I'm using broadcasts as well but some users want to use variables (they think its a more "grown-up" way of doing it).
I use Scratch with age7-11 year olds and don't use variables much so I'm happy to use broadcasts but I'm just try to please ALL my potential users
But you do loose some speed when using broadcasts instead of variables.
I never thought/realised that there would be a speed issue - I'm just controlling LEDs ans simulating Trafiic Lights at the moment. I'll have to check speed out once I start trying to build a line following robot
Do you think if Scratch was changed to do sensor-updates on set and change variable blocks it would break any code that you've written or know about?
Simon
PS
You could also do something like: sensor-update "test" "1 ignore everything after the first space" and just have the program ignore any extra data except for the first integer.
Didn't really understand this - its the fact that I can't get Scratch to send sensor-update messages, not any problem in dealing with them when I get them
Offline
SimpleScratch wrote:
I would suggest using broadcasts instead, since the same broadcast can be sent repeatedly without Scratch thinking "oh, I've already sent this, ignoring".
I'm using broadcasts as well but some users want to use variables (they think its a more "grown-up" way of doing it).
I use Scratch with age7-11 year olds and don't use variables much so I'm happy to use broadcasts but I'm just try to please ALL my potential users![]()
Yeah, variables would probably be a more "grown-up" way. But sometimes using the easier way can be more efficient depending on what you are doing.
But you do loose some speed when using broadcasts instead of variables.
I never thought/realised that there would be a speed issue - I'm just controlling LEDs ans simulating Trafiic Lights at the moment. I'll have to check speed out once I start trying to build a line following robot
![]()
The only reason broadcasts slow down Scratch, is because Scratch looks for any hats waiting to receive that block. It shouldn't make much of a difference as long as you aren't updating something more than 4 times a second.
Do you think if Scratch was changed to do sensor-updates on set and change variable blocks it would break any code that you've written or know about?
It wouldn't "break" any of my current projects or old ones, it would just remove some "potential" features. Like automatically stopping repeated messages on my future Chat server. But that isn't much of an issue. It won't be hard to create any scripts that stop duplicate messages from being sent for any future projects.
The main problem for me about changing Scratch to send updates every time a variable is updated (whether it's the same value or not) is saving bandwidth over the internet. But I'm sure there are things I can do to do that anyways.
You could also do something like: sensor-update "test" "1 ignore everything after the first space" and just have the program ignore any extra data except for the first integer.
Didn't really understand this - its the fact that I can't get Scratch to send sensor-update messages, not any problem in dealing with them when I get them
![]()
Basically, you send sensor-update "test" "1" the first time. Then you send sensor-update "test" "1 1" the second time. On the third you could do either sensor-update "test" "1" again or sensor-update "test" "1 2". You would have an external application that parses the value of "test" to see if there is any "useless" data added to the sensor-update and have it ignore that. Bypassing Scratch's "same value, ignore" routine.
Scratch sends "1" and the application sends 1 to the hardware.
Scratch sends "1 2" and the application sends 1 to the hardware.
Scratch sends "1" and the application sends 1 to the hardware.
Does that make more sense?
Offline
So does
set [var v] to (var)*not* send a sensor update?
Offline
You could make a variable value of something like "Ping!" which would just awake scratch. The RSC client would ignore that value.
Offline
You could make a variable value of something like "Ping!" which would just awake scratch. The RSC client would ignore that value.
No idea what you mean sorry
Its not a client issue, its Scratch not sending values it thinks its already sent and doesn't bother repeating even if you restart a script - its remembering stuff at a global level and not at a script level - I can't really artifically set the variables to other values in case I'm using it to control a Nuclear Power Station
Basically, you send sensor-update "test" "1" the first time. Then you send sensor-update "test" "1 1" the second time.
Same problem, dont want/should have to set artifical values to trick Scratch - I just think that it should take note of a Green Flag event and forget about what its sent in the past. (If it did jsut that and "wiped" its memory every Green Flag event, then that would do the job) - @MathWhizz - change file?????
Simon
Offline