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

#26 2013-01-11 02:38:18

s_federici
Scratcher
Registered: 2007-12-18
Posts: 500+

Re: Detecting fast repeated messages

nXIII wrote:

When a hat already has a process attached, it is replaced by the new process (at the beginning of the script, regardless of the previous process's position).

I feel like this is not the correct way Scratch should work. Not because it is wrong, but because this is not how people intuitively think it works. Even if re-entrancy works quite well almost for everything (3.000.000 projects can't be wrong...) I think that a sprite should be able to do something even if its hat is called again. And this without having to use "unnatural" variables. Maybe adding a "do not disturb" check button to hats (something reminiscent of BYOB's "atomic" check button) would make sense?

What do you think guys?

Offline

 

#27 2013-01-11 03:55:21

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: Detecting fast repeated messages

in BYOB and Snap the feature you're discussing seems to be the one named "thread safe scripts". Checking this disallows reentrancy of running scripts. Ideally there would also be options to not just ignore reentrancy events, but also to queue them...


Jens Mönig

Offline

 

#28 2013-01-11 05:32:15

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

Re: Detecting fast repeated messages

Yeah, it seems it should at least run the script at least until the first time it yields, for as many times as the broadcast is sent.


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

Offline

 

#29 2013-01-11 05:49:31

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: Detecting fast repeated messages

yielding doesn't have anything to do with aborting a thread, it's just a way of cooperating nicely  smile

The right way to think about this, of course, would be to have first-class threads  big_smile


Jens Mönig

Offline

 

#30 2013-01-11 05:58:48

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

Re: Detecting fast repeated messages

Jens wrote:

yielding doesn't have anything to do with aborting a thread, it's just a way of cooperating nicely  smile

I was thinking of the way Scratch runs the script until it gets to the bottom, or the bottom of a loop... what do you mean? I want to understand  tongue

The right way to think about this, of course, would be to have first-class threads  big_smile

First-class threads? How would that work? O_o


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

Offline

 

#31 2013-01-11 06:21:31

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: Detecting fast repeated messages

Well, ideally if you run a script you don't want it to stop executing unless it decides to do so itself. So force-aborting it when an event happens usually isn't what you would expect at all, regardless of whether that happens at the end of a loop or within a wait block. You want it to execute all the way and not kill it in between.

Usually.

The one exception I keep finding is synchronizing music in Scratch. That's the single one situation in which I *love* the ability to force-quit a running script (playing a note) and instead start a new one (playing another note) instantly.


Jens Mönig

Offline

 

#32 2013-01-11 07:08:49

Digimath
Scratcher
Registered: 2007-07-07
Posts: 100+

Re: Detecting fast repeated messages

s_federici wrote:

Digimath wrote:

So, then, the trick is to have each cow release control a different number of times before calling the score routine

Wow!!!!!!!!!!!! This is really cool! And, I shouldn't say this but I will say it: I knew there was a non-variable-based way of getting this result! It works incredibly well. I says incredibly as it is not really clear to me why it does work  smile  Any further detail/example?

As Jens put it, the scripts are yielding in a cooperative manner.  The different number of wait blocks per cow should mean that they are each doing a broadcast to the score script in a different dispatch loop instead of all doing it in the same loop.  I’ve never used this this technique before.  This is probably the hard way to control script priority – but an interesting study.


I've updated my text adventure game.
Colossal Cave 150http://scratch.mit.edu/static/projects/Digimath/3003787_sm.png

Offline

 

#33 2013-01-11 09:15:28

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Detecting fast repeated messages

Jens wrote:

Well, ideally if you run a script you don't want it to stop executing unless it decides to do so itself. So force-aborting it when an event happens usually isn't what you would expect at all, regardless of whether that happens at the end of a loop or within a wait block. You want it to execute all the way and not kill it in between.

So why doesn't that happen?

What about running a clone of that script every time it is called? As long as it doesn't conflict with itself, it should work, right?


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#34 2013-01-11 09:19:30

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

Re: Detecting fast repeated messages

Hardmath123 wrote:

Jens wrote:

Well, ideally if you run a script you don't want it to stop executing unless it decides to do so itself. So force-aborting it when an event happens usually isn't what you would expect at all, regardless of whether that happens at the end of a loop or within a wait block. You want it to execute all the way and not kill it in between.

So why doesn't that happen?

What about running a clone of that script every time it is called? As long as it doesn't conflict with itself, it should work, right?

If the same script could run in multiple "threads", the block flashing for single stepping would become meaningless/intensely confusing.  tongue


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

Offline

 

#35 2013-01-11 10:54:13

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: Detecting fast repeated messages

Hardmath123, a Scratch script is a thread, not a procedure. As such there can always only be a single instance, unless you fork it.


Jens Mönig

Offline

 

#36 2013-01-11 17:25:17

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Detecting fast repeated messages

s_federici wrote:

Do you have a full list of all yielding blocks?

Here:

Timed blocks (yield every frame including the final one):
<glide () secs to x: () y: ()>
<say () for () secs>
<think () for () secs>
<play sound () until done>
<play drum () for () beats>
<rest for () beats>
<play note () for () beats>
<wait () secs>
<wait until ()>
<broadcast () and wait>
<ask () and wait>

Special forms (yield after each loop iteration but don't yield when done):
<forever>
<repeat ()>
<forever if ()>
<repeat until ()>

Jens wrote:

Hardmath123, a Scratch script is a thread, not a procedure. As such there can always only be a single instance, unless you fork it.

No—a Scratch script is a set of instructions, and it has a one-to-one relationship with a thread wrapping that set of instructions; when this relationship maps to a non-null, running thread, the script is outlined in white. This relationship's cardinality could be changed to one-to-many, but it would be tricky to display feedback for that.

Last edited by nXIII (2013-01-11 17:26:42)


nXIII

Offline

 

#37 2013-01-12 07:18:37

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

Re: Detecting fast repeated messages

That's pretty comprehensive. Is that on the wiki somewhere, or can we add it?


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

Offline

 

Board footer