Help with variable context

untitled script pic(20)
so i tried recreating one of my old blocks with snaps new variadic handling, but for some reason, snap thinks the variable doesnt exist in the context, I even tried using the metaprogramming library to force the context of the caller on to the vaiables/set block but it still errors.

This block is like for each but it runs the action once everytime you click on it and using block variables it changes the variables when it is ran again. (EXAMPLE:


the first time the block is ran, then

the next time, etc)

Well, first of all, did you mean


?

Second of all, you'll have to teach me how you make a variadic upvar!

But also, I think the problem is that those upvars don't belong to the caller of your block, but rather to your block itself. So the CALLER OF CALLER OF is wrong. I think.

You can use the special "variables" input, which is the input the script variables block uses.
image

However you can't customize the default variable names, or min and max slots, but you can use metaprogramming.

Which you can then just edit the input like normal to choose default names, and min and max slots.
untitled script pic (85)

This is different from the "variables" input type, because it's literally just a variadic upvar, whereas the "variables" input type is a special type that can't be customized.

However it doesn't seem like the variables are even created, so you have to
manually create them before setting them.
Untitled script pic (86)
image

Even if you don't try to set the variable, it will also not exist
Untitled script pic (87)
image

So here's how I was able to get it to work.

Which runs this perfectly fine.

Untitled script pic (89)

P.S.

I just love how we're immediately doing weird things as soon as snap 10.0 released.

Edit: I've now fully figured out how to use it, and I created a new for each block.


Untitled script pic (91)

Another edit: apparently this was actually already possible in snap 8.

Based on
untitled script pic - 2024-07-25T003551.052

You may mutate the lambda ("action") to force the formal parameters

untitled script pic - 2024-07-25T014021.757


Do you know that block variables are "over-persistent" and there is no easy way to reset "item#" on green flag?


It can be simplified to vanilla :snap: (for single command)

Edit

restore initial context of the ""command"

yeah definitely my favorite snap update

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