Javascript code in reporter block

can I store javascript code in a custom reporter block (or variable)
and use it in a javascript block as a input?

Capture

doesn't work for me, doesn't returns anything

Functions can't do anything on their own.
I presume if you use it with a call block and add return happy; to the end of the line, it might. But I don't know much about how js local variables work.

Variables in JavaScript functions are only accessible within the function. You can:

  • Set a property of a global object (e.g. window, navigator, console, this (sprite)) in one function then get it in another.

[scratchblocks] run (JavaScript function \( @addInput \) \{ [window.myVar = "Hello, world!";] \} :: operators) @addInput :: control (call (JavaScript function \( @addInput \) \{ [return window.myVar;] \} :: operators) @addInput :: control) //Hello, world! [/scratchblocks]

  • Have a function return another function that accesses a variable then use it in a call block.

[scratchblocks] set [myVar accessor v] to (call (JavaScript function \( @addInput \) \{ [var myVar = "Hello, world!"; return function() {return myVar;};] \} :: operators) @addInput :: control) (call (myVar accessor) @addInput :: control) //Hello, world! [/scratchblocks]

*JavaScript

fixed.

I've found the solution

That monde would cause a syntax error unless svg.js ends with //.

just remove "monde", I forgot to delete it, it's "world" of hello world, look inside my project, https://snap.berkeley.edu/project?user=gego51&project=textured%203d%20cube, I have made some javascript blocks

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.