Discuss Scratch

dbal
Scratcher
5 posts

Return value from custom block

It is obviously possible to cause a custom block to store a return value in a global variable that is accessible by the calling code.

Is there a more direct way to cause a custom block created in v2.0 to return a value to the calling code?
scimonster
Scratcher
1000+ posts

Return value from custom block

Nope. 2.0 only supports stack blocks. A future version is planned to allow custom reporters and booleans.
dbal
Scratcher
5 posts

Return value from custom block

Thanks for the confirmation.
andre_rifaut
Scratcher
100+ posts

Return value from custom block

Well, if you do not want ot wait the future version it is actually possible to do that now.

Recall that a list is just an “infinite” number of single variables that you can dynamically create due to the variable size of the list.

Just use two lists: one with names, the other with the corresponding values. (If you want to improve the performance, you should use 1,2,3,… as variable names and skip the first list with names).

The drawback is that you have to manage yourself those dynamic variables instead of letting that managed by the scratch compiler.

Custom blocks seem to be accessible only by its own sprite/clone. So you can use list variables that are local to each sprite/clone.

Reki90
New Scratcher
9 posts

Return value from custom block

I made a block for Scratch Crash:
when green flag clicked
change [water ripple v] effect by (1)
Studio04040807
Scratcher
100+ posts

Return value from custom block

Reki90 wrote:

I made a block for Scratch Crash:
when green flag clicked
change [water ripple v] effect by (1)
That has nothing to do with any of this. This is a topic about making custom blocks report in a way besides
set [a variable v] to [ ]
drmcw
Scratcher
1000+ posts

Return value from custom block

Usually a good idea to check the dates on posts before jumping in.

Powered by DjangoBB