Multiple Input LET VAR BE Block

Just like the title says! The block in this project: Snap! 6.9.2 Build Your Own Blocks is the let block, but you can create multiple variables with it!


How it works: It first creates global variables, runs the the script and deletes them. Oh! The script stopped before it deleted the variables! Don't worry! It stores all the variables created and deletes them on the next run!

Umm. Maybe I'm not understanding something (such as for example the variable _NAME that's used but never declared and never set), but you can't just use global variables to simulate local variables. Suppose I have a global variable FOO. Now I say LET FOO BE 87 AND RUN something. You make a global FOO (which already existed), sert it to 87, run the something, and delete the global variable. That won't do. That's why we have script variables as a feature!

What you could do, much more easily, is use an association list (a/k/a a dictionary) to hold the names and values.

You should use multiple input upvars, (requires XML editing) and just loop through the var-list and set the specific vars to the corresponding item of the val-list:
[scratchblocks]
let ((a) :: grey) @addInput be [] @addInput :: grey
{+let+((vars...) :: grey)+be+((vals...) :: grey)+ :: grey} :: control hat
for ((i) :: control) = (1) to ([length v] of (vars) :: list) {
run ({set [ v] to (item (i) of (vals))} @addInput :: grey ring) with inputs (item (i) of (vars)) @delInput @addInput :: control
} :: control
[/scratchblocks]

That is what I did originally. You can't actually do that.

That is what I should have done. Thanks!

You can do that, but it requires a lot of compromise and some knowledge of XML editing.

I spent 2 hours yesterday trying to get that method to work.