How would I make a pointer to a variable?

I want to make a block that takes a variable as input and sets it internally. I've tried:

{scale{(var λ)::@addInput ring grey} by ((value)::variables)::variables}::hat control
set [var v] to ((var)*(value))


set [epic variable v] to (3)
scale {(epic variable)::ring grey} by (2) ::variables
//Just provides an error.

How would I actually make a pointer?

You have to use the run block to set the variable, and call the ring to get the value.


You beat me too it and a much neater method :slight_smile:

untitled script pic - 2023-11-08T174244.403


[Edit] In each of the above solutions the “variable” is an “Any (evaluated)” a Reporter input type. This requires a grey ring around the variable when calling the function. You can also use the “Any (evaluated)” type, as I will use below (no grey ring).[end of Edit]

One step beyond the “scale” block (which is similar to Programming tools DEVLAB script pic 27 but for the specific mathematical operation) is:

Application example

I actually wanted it for my own implementation of the for loop. The scale was just for simplicity's sake:

coreutils script pic

Do you know the concept of the upvar formal parameters? Ad'hoc, local variable, which can be set inside the function but is visible to the outer world.

I saw that. I can think of some uses...

Actually I used the reporter grey ring input type.

My mistake. I corrected it.

Just for fun I refactored several Snap! primitives some time ago. Below is my interpretation of the FOR-loop, with an upvar (i) of course:

After dropping the variable, the gray ring disappears and must be manually recreated...

I hadn't thought to use the SIGN function to set the increment! That's very elegant.

But instead of testing which tester to use each time through the loop, you could put that in a variable, too:

Maybe you already know how to do this and didn't for some reason, but instead of adding a loop arrow as title text I used the official loop arrow feature:

which puts the arrowhead at the right end of the actual block.


Agreed, much better.

I wasn't aware of the feature, even though I must have seen the tick box many times.

I'm truly looking forward to the results of Jens' project, coding Snap! primitives using Snap! itself!

How can i do if the var is a list ?
(change a list with a command block)(not a reporter...)

Can you clarify the question, perhaps with an example?

untitled script pic (6)

untitled script pic (7)

just a minute

not so urgent...

untitled script pic (3)

maybe This will work:
run {{replace item (1) of [ v] with (variable)}@addInput::reporter grey} with input (listVar)::control
(Sorry for the weirdness with the ""span class". The forum is interpreting the image's scratchblocks as a mention.) Here are the scratchblocks:

run {{replace item (1) of [ v] with (variable)}@addInput::reporter grey} with input (listVar)::control

You can try it on the [url=Discuss Scratch]To see