Possible to put variable directly into set()To()?

Hello, I was wondering if it was possible to directly input a variable into a set()To(), specifically for a forEach()In() loop. Currently, you seem to only be able to do this with the drop-down menu, but that eliminates the possibility of using it in a loop. For example, below I want to set each variable (a, b, c, d, e) to “Hello!”.

Mad Libs_ Copy script pic

However, the “item” variable doesn’t snap (ha, get it?) into the first parameter. The only other way to do the same thing would be to not use iteration at all, which would lead to seemingly unnecessary repetition. If there is a way around this or if I am not going about this correctly, I would appreciate the help. Thanks!

please read the FAQ before posting:

Oops, sorry. Thanks for pointing me in the right direction!

I still don’t understand, however. How could I make it work?

run ({set [ V] to [Hello!]} $> :: ring) with input ((a) $> :: ring) $< $> :: control

USE @snapenilk’s solution maybe not this one

xml script building script pic

drag this image into snap.

how (hidden because I hate advertising)

The first example in the project link of XML script builder v1.4.5, up to date as of snap 11.0.x!

(item)

needs to be ringified; here, it uses the value of item as the name of the variable to set

Huh. Seems silly to not allow users to directly input the variable into set()To(). Thanks anyhow.

Wait. What? Snap! just blocks that functionality? That seems very odd, especially if it works with a simple workaround. Thanks anyways!

The key is that you might read @sathvikrias’s solution to mean set the item variable to Hello, not the value of item itself. I would recommend not using @sathvikrias’s setup simply for readability. The FAQ sums it up quite nicely:

You can also use this block from the “Create variables” library:
untitled script pic (4)

Snap! just blocks that functionality? That seems very odd, especially if it works with a simple workaround.

Not so odd. We want to make it hard to put a variable in that slot casually (I was going to say “by accident” but that isn’t quite what I mean), but make it possible for an advanced user to do so with deliberation.

no, then it would set the item upvar to something, rather than the variable named as the contents of the upvar.

Either way, the variables in the list to iterate over need to be ringified.

yes.

Huh. So, how should I go about this? Which solution seems the most logical for effect and readability?

Probably using the Variables library is best. But it’s not a big deal.

Actually, the code will require a little tweaking to work with the variables library. Here’s why:


The library’s block won’t accept ringified variables. Instead, one must do something like this:

Or this:

Would you mind explaining why some of these work and others don’t? I’m quite lost…