Is there a way to convert desired global Vars of a Sprite to a Sprite specific Var type, with same name ?
I have been testing logic using one Sprite, and then when all works, I need to create clones of the Sprite with their own vars.
So I am looking for a shortcut to deleting and recreating all vars involved.
I played around with the Create Variables library with these results:
I declared a Global var: TEST.
Assigned a value to it: TEST=123
Then used the Create Sprite Var with the same name: TEST
It converted the TEST global var to a SPRITE var TEST. At least it looked like it in the variables list (it moved down with a "local" icon next to it):
But when I checkmarked it and tried to look at its reporter, it did not say "Sprite TEST", just TEST.
And any newly assigned value did not reflect correctly in the reporter.
That tells me things are not quite right in term of what I want to do and what is happening.
There's as of now no one-click way to change the scope of a variable, so you need to remove the declaration for one scope and re-declare the same variable name for another one. But: You only need to delete the variables in the palette and then make them again in a new scope. You can leave all the accessor blocks in place, because scope is late-bound, so all the blocks, reporters and commands alike, will work perfectly.
Oh, and please, for the love of computing stop using the variables library for stuff like this. I'm thinking about taking it out altogether, because apparently it entices people to believe that it's a good way to use variables. It is not! As a rule of thumb, whenever you feel the need to use the programmatic variables library your design is flawed and too complicated. I'm serious about this. Don't do it.
Think about any other programming language (except LOGO), not a single serious programming language supports declaring variables using a variable, it's a logical tautology and really, really wrong. @bh we should definitely think about getting rid of that library, it makes people think in circles and is really very wrong except maybe for curriculum developers.
Thanks for the pointer. It is a workable solution. So I am happy with it.
About the Variables library, I was only playing with it to see if I could get any results. But the results I got was not correct anyway.
Won't be doing no such thing in the future.