can I store javascript code in a custom reporter block (or variable)
and use it in a javascript block as a input?
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.
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, Snap! Build Your Own Blocks, I have made some javascript blocks
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.