This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#26 2012-03-23 12:46:10

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: kurt — Scratch file format Python library

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

 

#27 2012-03-23 13:55:11

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

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!  yikes
Please could you send me the project file that caused the bug? I'd like to take a look at it  smile

Last edited by blob8108 (2012-03-23 14:25:10)


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#28 2012-03-23 14:01:47

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

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.  smile


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#29 2012-03-23 14:09:11

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: kurt — Scratch file format Python library

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.  smile

Wow, this construct library seems really useful! I wish something like that existed for the .NETs  sad

I shall continue my search to find code that parses Scratch files.

Offline

 

#30 2012-03-23 14:22:07

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

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  smile


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#31 2012-03-23 15:58:52

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

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  smile

Ouch!  An entire OS! You could ask about specifics (version, hardware, etc.)


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#32 2012-03-23 16:43:55

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

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  smile

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  hmm


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#33 2012-03-23 16:46:33

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

Hmm...I'm running Python 2.6, that could change something. (it's pre-installed, so that could change something)


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#34 2012-03-23 17:04:02

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

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  smile

...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  tongue


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#35 2012-03-23 17:05:22

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

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  smile

...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  tongue

tongue   tongue   tongue  Wait, you can read this... sad


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#36 2012-03-25 04:42:34

roijac
Scratcher
Registered: 2010-01-19
Posts: 1000+

Re: kurt — Scratch file format Python library

blob8108 wrote:

roijac_test wrote:

awesome, just awesome  smile

and you're releasing it under... GPL3? please?
tongue

just want to know if we can use it on M30W  smile

I haven't actually decided yet  tongue  as permissive as possible, I think -- probably LGPL, or maybe Apache License... what licence would allow you to use it?  smile

well, i think apache, GPL(2+/3), and LGPL(2+/3) would all work, we're using GPL3  smile
wanna help? we need some python programmers  big_smile

Offline

 

#37 2012-03-25 06:58:10

s_federici
Scratcher
Registered: 2007-12-18
Posts: 500+

Re: kurt — Scratch file format Python library

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  smile

Offline

 

#38 2012-03-25 08:45:51

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

s_federici wrote:

Thanks a lot. Now everything works as expected.

Brilliant!  smile  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  smile

No worries; I've done the exact same thing many times before...  tongue


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#39 2012-03-29 17:56:34

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

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 heresmile

Last edited by blob8108 (2012-03-29 17:59:58)


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#40 2012-03-29 19:18:09

bobbybee
Scratcher
Registered: 2009-10-18
Posts: 1000+

Re: kurt — Scratch file format Python library

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 heresmile

Cool!


I support the Free Software Foundation. Protect our digital rights!

Offline

 

#41 2012-04-10 00:29:23

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: kurt — Scratch file format Python library

@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

 

#42 2012-04-10 03:32:54

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

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  smile


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#43 2012-04-10 04:20:47

roijac
Scratcher
Registered: 2010-01-19
Posts: 1000+

Re: kurt — Scratch file format Python library

guys, just join M30W  wink

Offline

 

#44 2012-04-10 04:45:46

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

roijac wrote:

guys, just join M30W  wink

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.  smile


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#45 2012-04-10 15:59:29

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: kurt — Scratch file format Python library

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

 

#46 2012-04-10 16:37:17

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

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  tongue ) — 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...  smile

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.  hmm

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...


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#47 2012-04-10 17:21:18

amcerbu
Scratcher
Registered: 2009-07-21
Posts: 500+

Re: kurt — Scratch file format Python library

blob8108 wrote:

I have a personal dislike for curly braces { } notation (they're kinda ugly  tongue ) — 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...  smile

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.  hmm

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

 

#48 2012-04-10 17:31:11

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

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.


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#49 2012-04-26 15:24:22

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: kurt — Scratch file format Python library

I just uploaded version 1.2, which now supports reading imagesbig_smile

Well, most images.  tongue  (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!  big_smile

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!  smile

Go on, have a look!

Last edited by blob8108 (2012-04-26 15:24:49)


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#50 2012-05-01 05:53:01

s_federici
Scratcher
Registered: 2007-12-18
Posts: 500+

Re: kurt — Scratch file format Python library

You are really doing an incredible job blob  smile  thanks a lot for all this!

Offline

 

Board footer