Discuss Scratch

Jonathan50
Scratcher
1000+ posts

Asynchronous Custom Blocks

Asynchronous Custom Blocks
What this is suggesting is the ability to make a custom block run in a separate thread, or run asynchronously from the caller script (script/s using the custom block). This would mean that the caller script could call the custom block and while the custom block is busy running in the background, do it's own stuff, even if the custom block had a forever loop.

This is sort of like comparing broadcast and broadcast and wait. Broadcast runs all receiving scripts and continues on the main thread while the receiver scripts are running, but broadcast and wait waits for all receiving scripts to finish before continuing. This would be especially useful for 1s1s projects.

Take this example: For a game, you could have a custom block that would handle arrow keys something like this:
when gf clicked
wait until <(start) = [1]>
handle controls until [stop]
repeat until <(stop) = [1]>
... // do other stuff
end

define handle controls until (end)
repeat until <((end) of [Stage v]) = [1]> // Sorry this has to be modified outside
if <key [left arrow v] pressed?> then // of Scratch ("hacked") because of an issue with my
point in direction (-90 v) // chosen example
move (speed) steps
end
if <key [right arrow v] pressed?> then
point in direction (90 v)
move (speed) steps
end
...
end
The two repeat until loops would run at the same time.

I think this could be a really useful feature for some Scratch projects. Here is a basic mockup of how this could work:


(I made a spelling mistake I'll fix it before I do another mockup)
(Also it should be “in”, not “on”)


Of course this could be different, and the text could be worded better and easier for New Scratchers or any Scratchers to understand.

Here is a new mockup (with spelling mistakes fixed):



Workaround
There is only one workaround that I know of (but it is not nice):
define async
...

when I receive [async v]
async

when gf clicked
broadcast [async v] // Always use BROADCAST ASYNC instead of the custom block
PS: If you don't understand some things about Scratch or general programming on this page, all the phrases in blue are links to a Scratch Wiki or Wikipedia article on the subject.

Last edited by Jonathan50 (May 21, 2019 09:00:01)


Not yet a Knight of the Mu Calculus.
Jonathan50
Scratcher
1000+ posts

Asynchronous Custom Blocks

Wait maybe run w/o screen refresh should be grayed out if run on separate thread is selected.
Also I made a spelling mistake in my mockup!
(I'll fix it in my next one if I do another one, maybe when I have more ideas and make run without screen refresh grayed out)
The mockup was made by modding Scratch 2.0, then screen recording using Microsoft Expression Screen Recorder, trimming and encoding was done in MS Expression, then finally using the GAP plugin extracted into GIMP, optimized and saved as a GIF, then uploaded to cubeupload and embedded in the forum post.

Last edited by Jonathan50 (Sept. 12, 2015 09:26:14)


Not yet a Knight of the Mu Calculus.
stickfiregames
Scratcher
1000+ posts

Asynchronous Custom Blocks

Semi-support, the workaround doesn't seem too hard.










If you can read this, my signature cubeupload has been eaten by an evil kumquat!




or you just used Inspect Element, you hacker

;
Jonathan50
Scratcher
1000+ posts

Asynchronous Custom Blocks

stickfiregames wrote:

Semi-support, the workaround doesn't seem too hard.
Added

Not yet a Knight of the Mu Calculus.
Gaza101
Scratcher
500+ posts

Asynchronous Custom Blocks

Support! How about a…
create thread and run :: control cstart
. . .
end
…block to make things easier? For example,
define example (threads)
repeat (threads)
create thread and run :: control cstart
. . .
end
end

Gaza101: retired member of the Scratch 2.0 Transition Team


DaSpudLord
Scratcher
1000+ posts

Asynchronous Custom Blocks

stickfiregames wrote:

Semi-support, the workaround doesn't seem too hard.


U^ェ^U::motion//This is Blocky. He lives in my signature. He is a trained attack block. He protects my siggy from kumquats.
Jonathan50
Scratcher
1000+ posts

Asynchronous Custom Blocks

Gaza101 wrote:

Support! How about a…
create thread and run :: control cstart
. . .
end
…block to make things easier? For example,
define example (threads)
repeat (threads)
create thread and run :: control cstart
. . .
end
end
Doesn't seem like a bad idea!
(this compares to the all at once block, for run without screen refrsh)

Last edited by Jonathan50 (Sept. 12, 2015 21:55:19)


Not yet a Knight of the Mu Calculus.
Jonathan50
Scratcher
1000+ posts

Asynchronous Custom Blocks

Ok I think, that threaded custom blocks shouldn't be able to run w/o screen refresh, and the checkbox should be grayed out, although, they can call run w/o screen refresh custom blocks.

Edit:

Last edited by Jonathan50 (Sept. 12, 2015 23:07:51)


Not yet a Knight of the Mu Calculus.
Jonathan50
Scratcher
1000+ posts

Asynchronous Custom Blocks

Bump

Not yet a Knight of the Mu Calculus.
Jonathan50
Scratcher
1000+ posts

Asynchronous Custom Blocks

Bump

Not yet a Knight of the Mu Calculus.
Prinseskat
Scratcher
1000+ posts

Asynchronous Custom Blocks

Support! I've thought about this before, and I see its uses. I know there's a workaround with broadcasts, but you could also workaround normal custom blocks with broadcast-and-wait blocks and variables for parameters… and that would be really annoying. Same logic applies here.

(also, I want to point out that in your example, the forever loop in
handle controls until ((stop) = [1])::custom
would either run forever or not at all depending on the value of
<(stop) = [1]>
at first - https://scratch.mit.edu/discuss/topic/65798/ is some random topic I found about this)

haha funny kumquat meme
Jonathan50
Scratcher
1000+ posts

Asynchronous Custom Blocks

Prinseskat wrote:

Support! I've thought about this before, and I see its uses. I know there's a workaround with broadcasts, but you could also workaround normal custom blocks with broadcast-and-wait blocks and variables for parameters… and that would be really annoying. Same logic applies here.

(also, I want to point out that in your example, the forever loop in
handle controls until ((stop) = [1])::custom
would either run forever or not at all depending on the value of
<(stop) = [1]>
at first - https://scratch.mit.edu/discuss/topic/65798/ is some random topic I found about this)
Ok!
(the example would be part of the game, but oh your right that would need lambda!
A basic workaround would be to pass the name of the variable as a string and use hacked blocks to make
((gend::custom-arg) of [Stage v])
)

Last edited by Jonathan50 (Sept. 15, 2015 09:23:30)


Not yet a Knight of the Mu Calculus.
Blank1234
Scratcher
500+ posts

Asynchronous Custom Blocks

workaroundable by using broadcast blocks
no support

Last edited by Blank1234 (Sept. 15, 2015 13:53:22)


Did you know that “kaj” means “and” in Esperanto?


















Totally not for SEO:
https://scratch.mit.edu/projects/85467306/
https://scratch.mit.edu/projects/83099266/
https://scratch.mit.edu/projects/81628056/
https://scratch.mit.edu/projects/81562288/
https://scratch.mit.edu/projects/81462110/
https://scratch.mit.edu/projects/81436112/
https://scratch.mit.edu/projects/78896920/
https://scratch.mit.edu/projects/78863998/
https://scratch.mit.edu/projects/76577776/
https://scratch.mit.edu/projects/76459270/
https://scratch.mit.edu/projects/74797364/
https://scratch.mit.edu/projects/74085188/
https://scratch.mit.edu/projects/73150274/
https://scratch.mit.edu/projects/73112658/
https://scratch.mit.edu/projects/72484040/
https://scratch.mit.edu/projects/72737486/
https://scratch.mit.edu/projects/72410420/
https://scratch.mit.edu/projects/72378152/
https://scratch.mit.edu/projects/71910314/
https://scratch.mit.edu/projects/67826618/
https://scratch.mit.edu/projects/67882676/
https://scratch.mit.edu/projects/66909070/
https://scratch.mit.edu/projects/66925858/
https://scratch.mit.edu/projects/66420350/
https://scratch.mit.edu/projects/66062314/
https://scratch.mit.edu/projects/65564542/
https://scratch.mit.edu/projects/64828196/
https://scratch.mit.edu/projects/64286296/
https://scratch.mit.edu/projects/64283600/
https://scratch.mit.edu/projects/62386850/
https://scratch.mit.edu/projects/63907584/
https://scratch.mit.edu/projects/62785306/
https://scratch.mit.edu/projects/63767660/
https://scratch.mit.edu/projects/62676562/
https://scratch.mit.edu/projects/61948978/
https://scratch.mit.edu/projects/62521426/
https://scratch.mit.edu/projects/61074988/
https://scratch.mit.edu/projects/11658256/
https://scratch.mit.edu/projects/60640274/
Sonickyle
Scratcher
1000+ posts

Asynchronous Custom Blocks

Support.

No I don't make projects anymore. I left some time ago.
I only check the forums every now and then, but other than that consider me retired.
Jonathan50
Scratcher
1000+ posts

Asynchronous Custom Blocks

Bump!

Not yet a Knight of the Mu Calculus.
BookOwl
Scratcher
1000+ posts

Asynchronous Custom Blocks

Support

who needs signatures
ChocolatePi
Scratcher
1000+ posts

Asynchronous Custom Blocks

Never mind

Last edited by ChocolatePi (Sept. 22, 2015 17:06:28)

Jonathan50
Scratcher
1000+ posts

Asynchronous Custom Blocks

Bump

Not yet a Knight of the Mu Calculus.
CatsUnited
Scratcher
1000+ posts

Asynchronous Custom Blocks

Support

bottom text
octad
Scratcher
59 posts

Asynchronous Custom Blocks

75% as per above.

Blank1234 wrote:

workaroundable by using broadcast blocks
no support
Blank, just because it's workaroundable does not necessarily justify or warrant a no support.

Powered by DjangoBB