Would it be hard for someone knowing Python and a C or .NET language to translate the code? I'd love to be able to integrate directly in certain projects of mine, and maybe I could even make an offline EXE player!
Offline
s_federici wrote:
Thanks a lot. Now I can run it. I got the following error when loading the provided game.sb:
Code:
>>> project = ScratchProjectFile('ciao.sb') Traceback (most recent call last): ... ArrayError: ('expected 34, found 16', ArrayError('expected 256, found 8', FieldError(FieldError('expected 2, found 1',),)))
Ooo! A bug!
Please could you send me the project file that caused the bug? I'd like to take a look at it
Last edited by blob8108 (2012-03-23 14:25:10)
Offline
LS97 wrote:
Would it be hard for someone knowing Python and a C or .NET language to translate the code? I'd love to be able to integrate directly in certain projects of mine, and maybe I could even make an offline EXE player!
Well, yes and no.
Python code is quite easy to read, and it's written using Construct, which is a declarative library for parsing in general -- declarative meaning you define the format, not the code for parsing the format. So it should document the format quite nicely.
However, I don't think there's an equivalent to the Construct library in C or .NET, or even any other programming language; making it quite hard to translate literally (without translating Construct too!). It might be easier to reverse-engineer the Java or Squeak code directly.
If you are trying to do this, it might be worth looking at the wiki where I collected together a bunch of information about the format, and might be more readable than my code.
Offline
blob8108 wrote:
LS97 wrote:
Would it be hard for someone knowing Python and a C or .NET language to translate the code? I'd love to be able to integrate directly in certain projects of mine, and maybe I could even make an offline EXE player!
Well, yes and no.
Python code is quite easy to read, and it's written using Construct, which is a declarative library for parsing in general -- declarative meaning you define the format, not the code for parsing the format. So it should document the format quite nicely.
However, I don't think there's an equivalent to the Construct library in C or .NET, or even any other programming language; making it quite hard to translate literally (without translating Construct too!). It might be easier to reverse-engineer the Java or Squeak code directly.
If you are trying to do this, it might be worth looking at the wiki where I collected together a bunch of information about the format, and might be more readable than my code.
Wow, this construct library seems really useful! I wish something like that existed for the .NETs
I shall continue my search to find code that parses Scratch files.
Offline
s_federici wrote:
Thanks a lot. Now I can run it. I got the following error when loading the provided game.sb:
Code:
>>> project = ScratchProjectFile('ciao.sb') ...
Terribly sorry; misread your post. From a quick test, this only happens on Windows. I'll investigate and let you know
Offline
blob8108 wrote:
s_federici wrote:
Thanks a lot. Now I can run it. I got the following error when loading the provided game.sb:
Code:
>>> project = ScratchProjectFile('ciao.sb') ...Terribly sorry; misread your post. From a quick test, this only happens on Windows. I'll investigate and let you know
Ouch! An entire OS! You could ask about specifics (version, hardware, etc.)
Offline
bobbybee wrote:
blob8108 wrote:
Terribly sorry; misread your post. From a quick test, this only happens on Windows. I'll investigate and let you know
Ouch! An entire OS! You could ask about specifics (version, hardware, etc.)
From the transcript, s_federici's using Python 2.7. I'm assuming the latest version of Construct; otherwise you'd get a different error. And I've reproduced the identical bug on my Windows setup; yet Ubuntu/Mac work fine, with identical versions. Gotta be Windows
Offline
Hmm...I'm running Python 2.6, that could change something. (it's pre-installed, so that could change something)
Offline
blob8108 wrote:
s_federici wrote:
Thanks a lot. Now I can run it. I got the following error when loading the provided game.sb:
Code:
>>> project = ScratchProjectFile('ciao.sb') ...Terribly sorry; misread your post. From a quick test, this only happens on Windows. I'll investigate and let you know
...I fixed it now. New version uploaded here.
It was rather trivial, as a matter of fact. I wasn't reading the files as binary files. *slaps self* [this apparently matters on Windows, but not on the *nixes.]
My apologies — I'll test on Windows too in future
Offline
blob8108 wrote:
blob8108 wrote:
s_federici wrote:
Thanks a lot. Now I can run it. I got the following error when loading the provided game.sb:
Code:
>>> project = ScratchProjectFile('ciao.sb') ...Terribly sorry; misread your post. From a quick test, this only happens on Windows. I'll investigate and let you know
...I fixed it now. New version uploaded here.
It was rather trivial, as a matter of fact. I wasn't reading the files as binary files. *slaps self* [this apparently matters on Windows, but not on the *nixes.]
My apologies — I'll test on Windows too in future
Wait, you can read this...
Offline
blob8108 wrote:
roijac_test wrote:
awesome, just awesome
and you're releasing it under... GPL3? please?
just want to know if we can use it on M30WI haven't actually decided yet as permissive as possible, I think -- probably LGPL, or maybe Apache License... what licence would allow you to use it?
well, i think apache, GPL(2+/3), and LGPL(2+/3) would all work, we're using GPL3
wanna help? we need some python programmers
Offline
blob8108 wrote:
...I fixed it now. New version uploaded here
Thanks a lot. Now everything works as expected. Sorry for not having answered before, I was monitoring this post page but my reply was the last one of page 1, and I didn't notice page 2
Offline
s_federici wrote:
Thanks a lot. Now everything works as expected.
Brilliant! I'm really pleased.
s_federici wrote:
Sorry for not having answered before, I was monitoring this post page but my reply was the last one of page 1, and I didn't notice page 2
No worries; I've done the exact same thing many times before...
Offline
I just posted a new version, v1.1, which adds:
* Block plugin formatter — reads all the scripts in a project file and outputs [scratchblocks] syntax code for posting on the Scratch forums/wiki.
* Scripts are now parsed properly; new Script and Block classes for manipulating scripts.
* General tweaks and improvements: proper Pythonic dict and list; more UserObject fields; Color is now parsed correctly.
Have a look here!
Last edited by blob8108 (2012-03-29 17:59:58)
Offline
blob8108 wrote:
I just posted a new version, v1.1, which adds:
* Block plugin formatter — reads all the scripts in a project file and outputs [scratchblocks] syntax code for posting on the Scratch forums/wiki.
* Scripts are now parsed properly; new Script and Block classes for manipulating scripts.
* General tweaks and improvements: proper Pythonic dict and list; more UserObject fields; Color is now parsed correctly.
Have a look here!
Cool!
Offline
@blob8108- Thanks for putting this together, it's great! I also support a Scratch IDE (hopefully for Scratch 2.0, just like all the other features people are wanting) that might allow both "code" and "blocks" modes.
Please check out the suggestion I posted on the Scratch Suggestions website a few days ago.
Offline
amcerbu wrote:
@blob8108- Thanks for putting this together, it's great! I also support a Scratch IDE (hopefully for Scratch 2.0, just like all the other features people are wanting) that might allow both "code" and "blocks" modes.
You could certainly write something like that using Kurt, and I've certainly been thinking about it. It's been suggested before a few times, I think.
How would you design the syntax — what would the code look like? Would it be a more forgiving version of [scratchblocks] — as Kurt can already convert to, but not from — or a different syntax? I'm still not sure about how to do it, so I'd appreciate any thoughts
Offline
roijac wrote:
guys, just join M30W
M30W has a GUI; if I made a text syntax thingy on top of Kurt, it'd be more of a converter.
ie., you would point it at your project, and it would decompile it to a folder for each sprite, perhaps, containing all the costumes as images, sounds as .wav files, and scripts as simple text files (probably containing [scratchblocks] syntax). There'd be another button to compile it back to the project again.
Offline
I imagine the IDE could resemble Scratch itself, in terms of the coloring and formatting of text. I support a C-style syntax that uses indentation and the { } notation for "blocks" (I think that's what they're called in C++). I also hope that if the Scratch team is to create a text-based IDE (in addition to the existing block-script interface), they will incorporate something like Microsoft's "IntelliSense," since the programmer no longer will have all the commands sorted and in front of him.
Offline
amcerbu wrote:
I imagine the IDE could resemble Scratch itself, in terms of the coloring and formatting of text. I support a C-style syntax that uses indentation and the { } notation for "blocks" (I think that's what they're called in C++).
I have a personal dislike for curly braces { } notation (they're kinda ugly ) — but I'll admit that's me being pretty arbitrary. I suppose one can never please everyone. I do think it'd be best if it were as simple/obvious as possible — no weird/unnecessary punctuation.
The argument for using [scratchblocks] syntax was that it's familiar — people already know how it works. (And I can already export to it, too!) But I'm open to other ideas, of course...
amcerbu wrote:
I also hope that if the Scratch team is to create a text-based IDE (in addition to the existing block-script interface), they will incorporate something like Microsoft's "IntelliSense," since the programmer no longer will have all the commands sorted and in front of him.
As I think you saw, I don't think the ST themselves will. But something like autocomplete? That would be useful; I can see your point there.
I still think exporting to plain text files, for editing with any text editor, is nicest; and syntax coloring/autocomplete could probably be added into most decent editors as a custom language plugin. It's probably easier to do that than write a whole new integrated editor...
Offline
blob8108 wrote:
I have a personal dislike for curly braces { } notation (they're kinda ugly ) — but I'll admit that's me being pretty arbitrary. I suppose one can never please everyone. I do think it'd be best if it were as simple/obvious as possible — no weird/unnecessary punctuation.
I admit, I used to not like them, but C#, C++, and RobotC have taught me otherwise.
blob8108 wrote:
The argument for using [scratchblocks] syntax was that it's familiar — people already know how it works. (And I can already export to it, too!) But I'm open to other ideas, of course...
I like the [scratchblocks] tags, although they are a bit awkward. An auto-complete would be very useful, since I often see Scratchers not quite getting the names of the blocks right.
blob8108 wrote:
As I think you saw, I don't think the ST themselves will. But something like autocomplete? That would be useful; I can see your point there.
Yeah. I'm not sure whether you're familiar with Visual Studio, but Microsoft's "IntelliSense" -- especially for C# and the other .NET languages -- is incredibly helpful. I suppose Scratch doesn't have to deal with having fathomless class libraries that no one knows completely, but some sort of "code correcting system" would be nice to deal with accidentally mistyped commands.
Last edited by amcerbu (2012-04-10 17:22:02)
Offline
amcerbu wrote:
Yeah. I'm not sure whether you're familiar with Visual Studio, but Microsoft's "IntelliSense" -- especially for C# and the other .NET languages -- is incredibly helpful. I suppose Scratch doesn't have to deal with having fathomless class libraries that no one knows completely, but some sort of "code correcting system" would be nice to deal with accidentally mistyped commands.
I have used IntelliSense, yes; and such a thing would indeed be useful. Then again, the correction could always be within the converter itself — ie. when you "compile" the project, it could automatically correct minor mistakes/differences, like "len" for "length of". Certainly a general principle of being as forgiving as possible seems appropriate.
Offline
I just uploaded version 1.2, which now supports reading images!
Well, most images. (It's very tricky.) And Kurt doesn't compress the images when saving them back to the file again (yet), so it may massively increase your file size...
(Reloading the project with Scratch, and saving it again, should fix this and other problems.)
—but it works!
There are a bunch of other tweaks too, of course.
And I also wrote a little utility — like the scratchblocks one for exporting scripts — that exports all the costumes in a Scratch project to separate PNG/JPG files, with a folder for each sprite. It automatically makes a folder called "<project name> files" to put the images in. Very useful, I'm sure!
Go on, have a look!
Last edited by blob8108 (2012-04-26 15:24:49)
Offline
You are really doing an incredible job blob thanks a lot for all this!
Offline