Change global variable to sprite and vice versa

This script lets you choose a variable and if it's a global - it will be converted to a sprite local one. If it's a sprite local one, it'll be changed to be a global.

[edit 15Aug] Now a custom command block

Trying to understand the benefit of
untitled script pic
which seems like the identity function to me!

Jens has always maintained that converting a global variable to a sprite variable can't be done cleanly, I guess because it would mess up references to that variable from other sprites. But I guess if you're doing it in your own project you presumably know what you're doing...

It's to utilise the dropdown variables menu of the library var reporter

AFAIK, we can't construct a reporter that would directly report the name of a variable with a menu

And I already had the name of var name custom reporter to hand

Well, I think this does it cleanly in the sense that it doesn't lose the contents of the variable

Scripts (other than one in the sprite that now contains the sprite local variables) would need to be adjusted if they needed to access the previous global variables

But I'm using this to sanitise my large Mayflower project (with its trillion global vars) and I can use my other find blocks/variable project to see which sprites are referencing them

It's keeping me off the streets :slight_smile:

Oh duh. I should have gotten that.

Turned it into a custom command to make it more compact to use within a sprite's scripting area


I'm really liking the ability to paste in these script pics that can hold everything needed to use them easily :slight_smile:

But I hate that yellow-green! :~P

Actually I think it's kind of weird for something so important to be a toggle. It should have a pulldown
and if the variable is already that scope it does nothing.

Who doesn't? :slight_smile:

But it does add to the effect of it being a dangerous block - but I'll play around with it and might make it a more standard bee/wasp warning colour :slight_smile:

I like your thinking - will change on next iteration :slight_smile:

Ok - changed the hue to pure yellow and using black capital labels


Hopefully, this should provide enough of a hint that this isn't a normal Snap! block and not to be used in a script

[edit] I think I prefer this labelling (30 secs after posting 1st version :slight_smile:


You think of
Untitled script pic - 2022-08-15T013446.232
Untitled script pic - 2022-08-15T014157.275
Untitled script pic - 2022-08-15T014153.845

Wait I'm confused now. Why can't you just

Screen Shot 2022-08-14 at 9.21.16 PM

@dardoro Lovely :slight_smile: I've tried for ages to get this - thank you very much :slight_smile:

If you just use the menu directly on an unevaluated input - you end up with a ringed result and not simply the name that Dariusz block gives

Incorporated @dardoro changes - I think we may have the final version :slight_smile:


So you use the variables list menu option for what the user sees, and Dariusz's code inside your block to get the name alone.

Yep :slight_smile:

If you want ONLY the variables list menu (no drag&drop) evaluated input is just enough.
untitled script pic - 2022-08-16T010743.673

I think my brain must have got confused in the past :slight_smile: