This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-08-27 13:14:59

SimpleScratch
Scratcher
Registered: 2007-05-25
Posts: 100+

RSC sensor updates not sending initial variable state

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

Code:

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

 

#2 2012-08-27 13:28:09

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: RSC sensor updates not sending initial variable state

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.  smile

Offline

 

#3 2012-08-27 13:38:06

SimpleScratch
Scratcher
Registered: 2007-05-25
Posts: 100+

Re: RSC sensor updates not sending initial variable state

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  smile

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  smile

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  smile

Offline

 

#4 2012-08-27 13:54:15

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: RSC sensor updates not sending initial variable state

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  smile

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  smile

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  smile

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

 

#5 2012-08-27 13:58:56

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: RSC sensor updates not sending initial variable state

You could have a second variable that changes by 1 every time you update the other variable.


http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#6 2012-08-27 14:41:59

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: RSC sensor updates not sending initial variable state

So does

set [var v] to (var)
*not* send a sensor update?


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#7 2012-08-27 14:44:36

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: RSC sensor updates not sending initial variable state

blob8108 wrote:

So does

set [var v] to (var)
*not* send a sensor update?

You are correct. It does not.


http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#8 2012-08-27 15:04:26

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: RSC sensor updates not sending initial variable state

You could make a variable value of something like "Ping!" which would just awake scratch. The RSC client would ignore that value.


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#9 2012-08-27 16:03:48

SimpleScratch
Scratcher
Registered: 2007-05-25
Posts: 100+

Re: RSC sensor updates not sending initial variable state

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  smile   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  smile

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?????  smile

Simon

Offline

 

Board footer