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
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
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
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
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
CHANGE VARIABLE ___ TO [GLOBAL | SPRITE LOCAL]
and if the variable is already that scope it does nothing.
Who doesn't?
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
I like your thinking - will change on next iteration
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
Do
You think of
Wait I'm confused now. Why can't you just
@dardoro Lovely I've tried for ages to get this - thank you very much
@bh
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
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
If you want ONLY the variables list menu (no drag&drop) evaluated input is just enough.
I think my brain must have got confused in the past