Calling a var from my blocks results in an error

I came up with this idea to be able to get the values of all the variables in the project by grabbing them from the (my [blocks]) list, and that worked.

Oly problem was, whenever I called a variable directly from the list, it results in an unidentified error.
image

(I turned off blurred shadows so the error was more noticeable)
Just to be clear, this works if calling the variable directly.


image

This does yield the same results with global variables.

I tested this same thing out with a normal reporter, and it worked as expected, no error.

It would be absolutely amazing if this was fixed, seeing as how it really doesn't make sense as to why it doesn't work.

blocks (procedures) need to be bound to an environment, otherwise they cannot access things like environment variables. Use the OF or ASK block to place them into a context.

Huh, that works, but if I'm able to call a variable directly, I'd expect to be able to call the same variable from the my blocks list, especially a global variable.

Also, if you're not going to fix it, at least add an error message.

A block isn't the same as a variable isn't the same as a procedure. If you didn't obsess so much about text you could actually learn a few things.

It just doesn't make sense for this to work
image

But not this
image
image

It's the same thing, yet it sill gives an error, and the bigger problem is, the error doesn't even say anything.

Isn't the environment, the sprite that is running the call block?

I can understand why a local variable needs to be called from the sprite it's in, but I can't understand why a global variable needs to be called from a sprite.

I don't know about this issue but a couple of things come to mind

Although a variable can be ringified and reports this

image

just because this looks to give the same result
image

doesn't mean it is the same type of result :slight_smile:

An analogy would be the difference (in a lot of other languages) between a number 123 and a string 123.

They both look the same when you print them out but are entirely different

I may have got this completely wrong but maybe it is the bridge between you and Jens :slight_smile:

Snap classifies it as the same thing

OK - so its not that then

What is your end goal in all of this?

Do you just want a two element list of variable names and their values?

There may be another method of getting there

To show that this is a bug that needs to be fixed.


After a bit more testing, I found out that this works
image

As well as this
image
image

Glad you've got a workaround :slight_smile:

Given Jens response to your issue and given all the other things he's said about similar issues, things like this are not considered to be bugs.

AFAIA, this breaking down of blocks into components has been created for some special purpose.

It doesn't seem to be intended for a lot of the use cases that the Snap! "hackers" want it to do.

I think querying this will not lead to a productive outcome. :slight_smile:

It wasn't a workaround for what I originally wanted to do. I wanted to be able to grab all the variables in any project, then be able to record them, to play them back later. Like the project recorders some users have made.

Are you interested in exploring methods using the create variables library?

Since you can extract the names of variables using your method, it shouldn't be too hard to then get their values using those library blocks

I don't want to use the create variables library if there's a way to do it without it.

a symbol needs to be put into a context to be be associated with a meaning. At the syntax-analysis level blocks are just that - symbols. You can take them apart and reassemble them. Then you put them into a context. Some blocks don't require an explicit context, e.g. the math operators, because they don't have side effects. Variables require an environment. There is no such thing as a "global" or "local" variable symbol, because variables are dynamically resolved at runtime. You don't want to assume the caller's environment because then you wouldn't need to use syntax-analysis/genesis at all, instead you can just use the blocks from the palette. Your tautological infatuation with meta-programming is getting on my nerves, because I keep having to point out that it doesn't lead to anything, it's all circular logic.

I found this bug too a while back in a BASIC to Snap! compiler I was writing. I solved it by compiling variable gets to the get variable block from the Create Variables library. But I didn’t think of using the ASK or OF block. That seems to be a better solution.

Fine. You win. At least add an error message.