I think it would be very nice to be able to right-click a variable and change its name, perhaps you've decided to use it differently than originally intended (or have come to dislike its name for whatever reason), yet it exists in many scripts.
Probably a bit more difficult to implement, but perhaps even more useful:
The ability to right-click a variable and get a menu that would let you make a Local variable "go Global" or a Global variable become Local (which could only happen if just one Sprite used it).
While I'm wishing, how about this. Right Click a variable and get a menu that says:
--Rename
--Make Local (greyed out if it already is or if more than one sprite uses it)
--Make Global (greyed out if it already is)
--Used By...
Missile (3)
Tank (1)
Background (2)
("Used By" would fly out a list of the Sprites that use the variable, clicking on a Sprite name in the list would "take you to" that Sprite.) This would be nice to have for cleaning up a project, I might realize that only one other Sprite uses a Global variable and that I could Broadcast to it instead. Icing on the cake would be the number of times each Sprite "calls" the variable in its scripts.
Offline
More on variables:
Another thought occurred to me after some serious head-Scratching during debug of a script that just didn't do what I was sure it should. It turned out that I had created and used a local variable one evening, later came back and decided that the same information was needed in other Sprites, so I made a Global with the exact same name (forgetting about the previously created "local"). The variables worked just as they should have, but it sure had me confused for a while.
I think that it would be nice to "disallow" Locals and Globals with the same name, or at the very least make the colors more different for the two types of Variable Blocks.
Yes, you can avoid this by planning more carefully and keeping a written list of variables, but my Scratching often goes on late in the evening and an hour or two at a time, so I'll (ask for) all the help I can get.
Still wishing:
How about an "Extra", that makes a text file listing all of the project's variables. First all of the Globals, then Locals by Sprite?
Offline
Yes, I made the same comment months ago---the colors are too similar and you should never be able to have a local and global with the same name. If the local name always included the sprite name (as it does in the variable displays on the screen), the problem would be solved.
The idea of being able to get a variable list (that include all vairables, not just those accessible from the current sprite), is a good one.
Offline
Good suggestion, I like it.
Offline
Even if is not yet possible to change a variable name by right-clicking it, is there a maybe more complex way of doing it? Without having to deep-scanning all the scripts? Even an hard-coding work on the sb file could be good to me. I'd would like to be able to do this as I'm now translating to Italian some very good educational programs developed in Scratch and I need to be able to show variables with Italian "captions" to my young Italian kids.
Thanks in advance for any help
Offline
I'm not sure, but in theory the programs are stored, on some level, as text. So For somebody in the know (Jens?) might be able to come up with a way to do an unofficial "Search and Replace"...
Offline
Hi s_federici and Mayhem,
I am indeed fantasizinig about churning out some sort of add-on tools for the Scratch "workbench" (pardon me, for the 'based on Scratch' workbench, of course...), but alas, time is lacking.
A couple of months ago I posted a Scratch-XML converter on SqueakMap for v.1.1 which allows you to export any Scratch script (blocks or stacks of blocks) into an XML file which can be edited using any text editor and then be re-imported into Scratch. That way you can just use the search/replace function of your text editor to rename all variable names in a script.
This only integrates correctly into v.1.1, though.
I haven't gotten around to updating my XML tool to the new official v.1.2.1 source code version, since it was just a quick feasibility study I did for some teacher friends of mine who at the time were looking for a 'text-editor-version' of Scratch. If there is any serious interest in this, I'd be willing to try and post an update (to where?).
Offline
Jens,
I think your text editor would be really useful, I find Scratch a bit cluttered sometimes and it would be good to be able to edit it directly on something like notepad.
SB
Offline
Hi Jens,
that wuld be really great. I also looked for references to SquakMap but I couldn't find any link, neither in this site nor in squeak's site. Would you mind posting a link to it? Thanks.
Offline
Hi s_federici and ScipioBellorum,
I just did a quick and dirty port of my xml2scratch interface to version 1.2.1 and packaged it all into a Scratch tutorial project which you can look at and download here:
http://scratch.mit.edu/projects/Jens/93504
Please feel free to play with the code, and to alter and modify it according to your needs, just be aware, that this is 1) probably not really what you're looking for, and 2) in no way production quality code, i.e. you'll most probably encounter some bugs and errors.
Offline
Hi Jens,
thanks a lot for your help with this. Your hack to Scratch is really interesting and I think will help a lot the Scratch community.
I don't want to seem not grateful to you for the beautyful work you did but I think that what I need is a more general way of changing all variable names of a given variable in the scratch code by means of a single operation. I guess that I could use your hack but that I should export and then reimport every single script. Is this true? Or did I misunderstood your instructions?
Thanks again and congratulations again for the very nice work
Stefano
Offline
Hi Stefano,
the xml project I mentioned does not provide an easy way to rename variables, it's just something I sort of had in my drawer, which lets you export Scratch scripts into an editable text format, albeit one very hard to make sense of in a plain text editor, because it comes totally unformatted (there is a method to produce a formatted file somewhere in the code, though).
In practice you would need to export each script containing a variable reference, edit each file to rename the referenced variable name, import the edited script back into Scratch and fix some possibly broken references to other sprites, then delete the original script and finally remove the 'old' variable. Doesn't exactly sound like a power-editing tool, and it is not!
Threrefore I do not recommend using this xml interface to rename variables from English to Italian in a sprite or project, since it is most likely much easier to accomplish this by just manually replacing the English variable names with corresponding Italian ones in Scratch. My xml project is really just an ugly hack, at best a starting point from which to set out for other truly useful creations.
Offline
Thanks for your explanation Jens. So I need something else but be sure, as I said, that your tool is certainly useful.
So I'm now asking the Scratch Team: is there somewhere a (clear or not) explanation of the SB file format? Or this is something that comes directly out of Squeak and it is too complex to be parsed with a homemade tool?
Offline
Stefano,
John has posted an explanation of the binary Scratch Project File Format on the Sources page (http://scratch.mit.edu/pages/source) here:
http://scratch.mit.edu/files/source-code/ScratchFileFormat.txt
But I seriously doubt that you'll be able to emulate a parser for that format using homemade tools with any reasonable effort. Your best try would be to download the Scratch sources and try the Squeak environment, since it already has everything you need including the object store mechanism nicely integrated. Personally, though, I'd be extremely reluctant to fiddle around with the binary file format of Scratch projects used by the official Scratch version (and by the website), because chances are good that you'll break compatibility in trying so.
Offline
Thanks for your help Jens. I will start digging the file format and then... maybe I'll pass to Squeak :-)
Offline
Hi Stefano,
I think I have just come up with an even easier way to change the variables from English to Italian, if you just use the variable blocks renaming feature of my new "options" project:
http://scratch.mit.edu/projects/Jens/103320
This is how you would do it:
1. Create a new Italian variable for every English one you want to rename
2. Right click on every block referring to an English variable and choose the Italian one
3. Delete all redundant (English) variables
A bit tedious but definitely a lot easier than fiddling around with binary file formats. I'd be interested to know if it works for you...
Offline
A bit tedious?!?!? This is the smarter way I saw till now to rename variable!!! I can't believe it... I'm testing it IMMEDIATELY!!!
PS: is there a mechanism on the scratch site so that every time someone you have defined as an "I want their script!" guy (e.g. you...) publish a new project? I tried surfing the site to look for interesting projects and I collected about 700. But I can see that there are more than 70000 projects on the site (a hundred times the amount I collected!). And you get soon lost without (maybe) being able to find the ones that are really important to you. Even tags (I use a lot tags in my surfing) are a weak strategy. The most successful until now is: looks for every project of the authors of a project you like and for everyone of their favorite projects, and so on and so forth...
Offline
Look for the Subscribe button when viewing a persons projects. It will set up an RSS feed that will tell you when that person has posted a new project.
Offline
I didn't notice it! Thanks a lot.
Offline
I just did an extensive test to find out if renaming variables by swapping one for another using this patch works, and I'm glad to announce that it does for me. Whatsmore, I was able to keep the test project *running* while trying this dynamically (Scratch is fantastic!).
Offline
Why did my comment get removed? I see no reason why it was.
Offline