Shared variables

For block variables, script variables, and local variables, there would be an option to share the variable. What this means is, you can share variables in one script with another script.

Why can't you just make it a global or sprite-local variable?

For DevSquare, you don't want all the engine variables clogging up the user's variables

then make the engine its own sprite with its own sprite-local variables

he was just giving an example

Only one person is on my account.

i was using they as a gender-neutral pronoun

It's a he.

I'm not sure which of at least two possible things you're suggesting. But that's okay because I want (some version of) both of them, too. :~)

  1. Block A, which is running, calls block B. Block B wants to use a script variable or an input of block A. This feature is called dynamic scope. You and I aren't going to get precisely that feature, because it'd slow down Snap! unacceptably. But at the recent History of Programming Languages conference someone mentioned a way to get the virtues of dynamic scope efficiently and without name capture bugs, so I have to track that down and look into it. On my list for when Snap!Con is over...

  2. Blocks A, B, and C work together to provide some feature, like a library. They maintain some state information, e.g., in the Colors library, what scale you used the last time you set the pen color. All those blocks need access to these state variables but nobody outside the library does. We can do that with blocks that report a lambda (ringed) function, but it's a pain to use because you have to store the function in a variable and use CALL to call it, instead of having a block in the palette. I think that if I get macros implemented (don't hold your breath) they might solve this problem. Although Jens hates the idea of program-generated palette blocks.

I'm not sure how this would work... Don't get me wrong, I think this idea is great, it's just, how would one choose the scripts that can use the variable. I also think this is also kind of useless since we already have global and local variables.

You mean the shared local state one? Because dynamic scope is just based on who called whom.

So, say you have a block like this one from dardoro:


Now imagine that if you use this block inside a custom block it has access to that block's environment. So all the blocks you define within that "block factory" block would share the same state variables ("state" as in, doesn't disappear when the block finishes running).

ok

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