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

#1 2012-02-12 09:29:43

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

A new XML file format for 2.0

The file format for 2.0 projects should be XML, and should work similar to snap (the sequel to BYOB)
The top-level code will be

<project name=project name>
  <notes>
     project notes
  </notes>*
  <thumbnail>
    base-64 encoded image
  <blocks>
     custom block definitions, see below
  </blocks>*
  <stage background=stage background number>
    stage declaration, see below
  </stage>
  <sprites>
    sprite declarations, see below
  </sprites>
  <var-watcher var=variable name x=watcher x y=watcher y readout=readout (normal, large or slider) slider-min=slider min** slider-max=slider max**/>*
   ...
    <list-watcher list=list name x=watcher x y=watcher y w=width h=height/>*
   ...
</project>

*omitted if there are none
**only for sliders

Custom blocks: (confirmed 2.0 feature)

<blocks>
  <block-definition catograry=catograry (motion, control, ect)scope=scope* type=either stack, reporter or Boolean>
    <block-name>
       first bit of block name <block-input type=input type** default=default value>input name</block-input>second bit of block name ...
     </block-name>
     <script hat='block-definition'>
       block script, see below
     </script>
  </block-definition>
  ...
</blocks>

*what objects can use it, either sprites, stage or global
**either number, string or Boolean (or drop-down if it is implemented)

Stage/sprite declarations:

<stage background=stage background number>
  <variables>
    variable declarations, see below
  </variables>
  <media>
    media declarations, see below
  </media>
  <scripts>
    scripts, see below
  </scripts>
</stage>
<sprites>
  <sprite name=sprite name x=x position y=y position dir=sprite direction costume=costume number hidden='hidden'* rotate=rotation style either normal, flip or none>
    <variables>
      variable declarations
    </variables>
    <media>
      media declarations
    </media>
    <scripts>
      scripts
    </scripts>
  </sprite>
  ...
</sprites>

*omit if sprite is shown

Variable declarations:

<variables>
  <variable name=var name>value</variable>
  ...
  <list name=list name>
    <item>value,</item>
    ...
  </list>
  ...
</variables>

*omit if watcher is hidden
**only if readout is slider

Media:

<media>
  <costume name=costume name rotationx=costume center x* rotationy=costume center y*>
    <text x=x position of text layer* y=y position of text layer* size=text size font=text font>text content</text>
    ...
    <image>base-64 encoded image</image>
  </costume>**
  ...
  <sound name=sound name>base-64 encoded sound</sound>
  ...
</media>

* relative to top-left corner of costume
**on the stage it is background not costume and there is no rotation center

Scripts:

<scripts>
  <script hat=script hat* input=hat block input**>
    <block type=stack, report or Boolean>first bit of block name, for example 'move'<input type=input type***>value****</input>2nd bit of block name, for example 'steps'   ...<c-mouth>If it is a c-block, script goes in here. If not, omit the c-mouth bit</c-mouth></block>
    ...
  </script>
  ...
</scripts>

*either 'green-flag', 'receive','key-pressed'or 'sprite-clicked'
**only for receive and key-pressed
***either 'number', 'string', 'reporter','Boolean', 'drop-down' , 'variable-name' 'list-name'. 
****if it is a Boolean or reporter this will be another block tag.

Here is a DTD:

Code:

<!DOCTYPE project [
<!ELEMENT project (notes?, blocks?, stage, sprites, (var-watcher|list-watcher)*)>
<!ELEMENT notes (#PCDATA)>
<!ELEMENT thumbnail (#PCDATA)>
<!ELEMENT var-watcher (#EMPTY)>
<!ELEMENT list-watcher (#EMPTY)>


<!ATTLIST var-watcher var-name IDref #REQUIRED>
<!ATTLIST var-watcher x CDATA #REQUIRED>
<!ATTLIST var-watcher y CDATA #REQUIRED>
<!ATTLIST var-watcher readout (normal|large|slider) normal>
<!ATTLIST var-watcher slider-min CDATA 1>
<!ATTLIST var-watcher slider-max CDATA 10>

<!ATTLIST list-watcher list-name IDref #REQUIRED>
<!ATTLIST list-watcher x CDATA #REQUIRED>
<!ATTLIST list-watcher y CDATA #REQUIRED>
<!ATTLIST list-watcher w CDATA 95>
<!ATTLIST list-watcher h CDATA 115>


<!ELEMENT blocks (block-definition*)>
<!ELEMENT block-definition (block-name, script)>
<!ELEMENT block-name ((#PCDATA|block-input)*)>
<!ELEMENT block-input (#PCDATA)>


<!ATTLIST block-definition catograry, (motion|control|looks|sensing|operators|pen|sound|variables|lists|other)  #REQUIRED>
<!ATTLIST block-definition scope (sprites|stage|global) global>
<!ATTLIST block-definition type (stack|reporter|boolean) stack>

<!ATTLIST block-input type (number|string|boolean) string>
<!ATTLIST block-input default CDATA #IMPLIED>


<!ELEMENT stage (variables, media, scripts)>
<!ELEMENT sprites (sprite*)>
<!ELEMENT sprite (variables, media, scripts)>


<!ATTLIST stage background CDATA #REQUIRED>

<!ATTLIST sprite name ID #REQUIRED>
<!ATTLIST sprite x CDATA #REQUIRED> 
<!ATTLIST sprite y CDATA #REQUIRED>
<!ATTLIST sprite costume CDATA #REQUIRED>
<!ATTLIST sprite hidden (hidden|shown) shown>
<!ATTLIST sprite rotation (normal|flip|none) normal)>


<!ELEMENT variables (variable*, list*)>
<!ELEMENT variable (#PCDATA)>
<!ELEMENT list (item*)>
<!ELEMENT item (#PCDATA)>


<!ATTLIST variable name ID #REQUIRED>

<!ATTLIST list name ID #REQUIRED>


<!ELEMENT media ((costume*|background*),sound*)>
<!ELEMENT costume (text*,image)>
<!ELEMENT background (text*, image)>
<!ELEMENT text (#PCDATA)>
<!ELEMENT image (#PCDATA)>
<!ELEMENT sound (#PCDATA)>

<!ATTLIST costume name ID #REQUIRED>
<!ATTLIST costume rotationx CDATA #REQUIRED>
<!ATTLIST costume rotationy CDATA #REQUIRED>

<!ATTLIST background name ID #REQUIRED>

<!ATTLIST text x CDATA #REQUIRED>
<!ATTLIST text y CDATA #REQUIRED>
<!ATTLIST text size CDATA #REQUIRED>
<!ATTLIST text font CDATA #REQUIRED>

<!ATTLIST sound name ID #REQUIRED>


<!ELEMENT scripts (script*)>
<!ELEMENT script (block*)>
<!ELEMENT block ((#PCDATA|input|c-mouth)*)>
<!ELEMENT input (#PCDATA|block)>
<!ELEMENT c-mouth (block*)>


<!ATTLIST script hat (green-flag|receive|key-pressed|sprite-clicked|block-definition) green-flag>
<!ATTLIST script input CDATA #IMPLIED>

<!ATTLIST block type (stack|reporter|boolean) stack>

<!ATTLIST input type (number|string|boolean|drop-down|variable-name|list-name)>
]>

There would be an application to convert old .sb files into this format.

Advantages:
You could make a scratch project in notepad without scratch installed!
Smaller file size,
Recognized by tons of programming languages,
Easy to store on the internet,
You can copy scripts, costumes, and even entire sprites to another scratch window,
Easy to read and write by humans,
Projects will load faster.

Last edited by joefarebrother (2012-04-13 06:10:57)


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#2 2012-02-12 09:36:49

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: A new XML file format for 2.0

That would be so great!

Offline

 

#3 2012-02-12 09:48:33

SJRCS_011
Scratcher
Registered: 2011-02-07
Posts: 1000+

Re: A new XML file format for 2.0

I like it.
especially editing using notepad

Last edited by SJRCS_011 (2012-02-12 11:18:17)


http://i.imgur.com/vQqtH.png
Learning to Program in a Nutshell:  "You're missing a closing parentheses" - LS97

Offline

 

#4 2012-02-12 11:01:45

veggieman001
Scratcher
Registered: 2010-02-20
Posts: 1000+

Re: A new XML file format for 2.0

I agree;; this would be bloody excellent. Especially with the custom blocks, so then there could be a block repository like the Library where you could add blocks really easily.


Posts: 20000 - Show all posts

Offline

 

#5 2012-02-12 11:35:54

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: A new XML file format for 2.0

SJRCS_011 wrote:

I like it.
especially editing using notepad

Almost like text based Scratch!

veggieman001 wrote:

I agree;; this would be bloody excellent. Especially with the custom blocks, so then there could be a block repository like the Library where you could add blocks really easily.

Yay, the Block Library won't have to die with an update!

Except I'm 99.9% sure this won't make it into the 2.0 release. Maybe sometime later though!

Last edited by scimonster (2012-02-12 11:36:15)

Offline

 

#6 2012-02-12 11:59:04

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

Re: A new XML file format for 2.0

this suggestion is the best  smile

Offline

 

#7 2012-02-14 20:00:24

SJRCS_011
Scratcher
Registered: 2011-02-07
Posts: 1000+

Re: A new XML file format for 2.0

maybe for the scripts section we could use the block plugin syntax.
As for the DTD, why not do something like the HTML doctypes, so like this:

Code:

<!DOCTYPE SCRATCH public "scratch.mit.edu/dtd/Scratch_2-0/final.dtd">

where "final.dtd" contains all of this:

Code:

<!ELEMENT project (notes?, blocks?, stage, sprites)>
<!ELEMENT notes (#PCDATA)>
<!ELEMENT blocks (block-definition*)>
<!ELEMENT stage (variables, media, scripts)>
<!ELEMENT sprites (sprite*)

<!ATTLIST stage background CDATA #REQUIRED>

<!ELEMENT block-definition (block-name, script)>
<!ELEMENT block-name ((#PCDATA|block-input)*)>

<!ATTLIST block-definition catograry, (motion|control|looks|sensing|operators|pen|sound|variables|lists|other)  #REQUIRED>
<!ATTLIST block-definition scope (sprites|stage|global) global>
<!ATTLIST block-definition type (stack|reporter|boolean) stack>
<!ATTLIST block-input type (number|string|boolean) string>
<!ATTLIST block-input default CDATA #IMPLIED>

<!ELEMENT variables (variable*, list*)>
<!ELEMENT media ((costume*|background*),sound*)>
<!ELEMENT scripts (script*)>
<!ELEMENT sprites (sprite*)>
<!ELEMENT sprite (variables, media, scripts)

<!ATTLIST sprite name ID #REQUIRED>
<!ATTLIST sprite x CDATA #REQUIRED> 
<!ATTLIST sprite y CDATA #REQUIRED>
<!ATTLIST sprite costume CDATA #REQUIRED>
<!ATTLIST sprite hidden (hidden|shown) shown>
<!ATTLIST sprite rotation (normal|flip|none) normal)>

<!ELEMENT variable (#PCDATA)>
<!ELEMENT list (item*)>
<!ELEMENT item (#PCDATA)>

<!ATTLIST variable name ID #REQUIRED>
<!ATTLIST variable watcher (shown|hidden) hidden>
<!ATTLIST variable watcherx CDATA #REQUIRED>
<!ATTLIST variable watchery CDATA #REQUIRED>
<!ATTLIST variable readout (normal|large|slider) #REQUIRED>
<!ATTLIST variable slidermin CDATA 1>
<!ATTLIST variable slidermax CDATA 10>
<!ATTLIST list name ID #REQUIRED>
<!ATTLIST list watcher (shown|hidden) hidden>
<!ATTLIST list watcherx CDATA #REQUIRED>
<!ATTLIST list watchery CDATA #REQUIRED>
<!ATTLIST list watcherw CDATA 95>
<!ATTLIST list watcherh CDATA 115>

<!ELEMENT costume (text*,image)>
<!ELEMENT background (text*, image)>
<!ELEMENT text (#PCDATA)>
<!ELEMENT image (#PCDATA)>

<!ATTLIST costume name ID #REQUIRED>
<!ATTLIST costume rotationx CDATA #REQUIRED>
<!ATTLIST costume rotationy CDATA #REQUIRED>
<!ATTLIST background name ID #REQUIRED>
<!ATTLIST text x CDATA #REQUIRED>
<!ATTLIST text y CDATA #REQUIRED>
<!ATTLIST text size CDATA #REQUIRED>
<!ATTLIST text font CDATA #REQUIRED>

<!ELEMENT script (block*)>
<!ELEMENT block ((#PCDATA|input|c-mouth)*)>
<!ELEMENT input (#PCDATA|block)>
<!ELEMENT c-mouth (block*)>
<!ELEMENT blank-input EMPTY>

<!ATTLIST script hat (green-flag|receive|key-pressed|sprite-clicked|block-definition) green-flag>
<!ATTLIST script input CDATA #IMPLIED>
<!ATTLIST block type (stack|reporter|boolean) stack>
<!ATTLIST input type (number|string|boolean|drop-down|variable-name|list-name)>

("final" could be "beta" for beta version, "alpha" for alpha version, etc.)

Last edited by SJRCS_011 (2012-02-14 20:02:19)


http://i.imgur.com/vQqtH.png
Learning to Program in a Nutshell:  "You're missing a closing parentheses" - LS97

Offline

 

#8 2012-03-01 12:35:27

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: A new XML file format for 2.0

SJRCS_011 wrote:

maybe for the scripts section we could use the block plugin syntax.

well how would you define c-blocks?


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#9 2012-03-01 13:25:13

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: A new XML file format for 2.0

This sounds brilliant!  It will work like the Text Based Scratch idea that many users want, but instead of having to program a complicated new mode into 2.0, they can just change their code to be human-readable XML files!  That way, advanced users can have the experience of text-based coding, without the risk of confusing newer users!

I wholeheartedly support!   big_smile

Offline

 

#10 2012-03-01 15:57:57

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

Re: A new XML file format for 2.0

File size is an issue. Binary is more efficient than ASCII--the file limit of 10 MBs would store so much less.


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

Offline

 

#11 2012-03-01 16:30:55

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: A new XML file format for 2.0

bobbybee wrote:

File size is an issue. Binary is more efficient than ASCII--the file limit of 10 MBs would store so much less.

How about at least having it as an option?

Offline

 

#12 2012-03-01 17:13:49

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

Re: A new XML file format for 2.0

That would work well. Really well.


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

Offline

 

#13 2012-03-03 13:59:25

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: A new XML file format for 2.0

bobbybee wrote:

File size is an issue. Binary is more efficient than ASCII--the file limit of 10 MBs would store so much less.

Well, the 10MB limit is going to be raised...

Offline

 

#14 2012-03-03 15:14:11

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

Re: A new XML file format for 2.0

bobbybee wrote:

File size is an issue. Binary is more efficient than ASCII--the file limit of 10 MBs would store so much less.

i'm not sure - the binary object serialization is actually not so efficient...
did you guys ever notice scratch knows about every time we saved the project?!

Offline

 

#15 2012-03-03 15:18:16

ProgramCAT
Scratcher
Registered: 2011-12-13
Posts: 500+

Re: A new XML file format for 2.0

I support!


Programming is an art...
Goodbye, Scratch. I am leaving because of the exams coming up at our school, though I'll check the forums once or twice a week.

Offline

 

#16 2012-03-03 15:29:12

logiblocs
Scratcher
Registered: 2010-05-05
Posts: 100+

Re: A new XML file format for 2.0

How could I not support?

Offline

 

#17 2012-03-03 15:59:25

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

Re: A new XML file format for 2.0

roijac wrote:

bobbybee wrote:

File size is an issue. Binary is more efficient than ASCII--the file limit of 10 MBs would store so much less.

i'm not sure - the binary object serialization is actually not so efficient...
did you guys ever notice scratch knows about every time we saved the project?!

If these things were improved, the file sizes would go down. A lot.


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

Offline

 

#18 2012-03-03 16:22:54

trinary
Scratcher
Registered: 2012-01-29
Posts: 1000+

Re: A new XML file format for 2.0

Definitely, if it is possible...


http://trinary.tk/images/signature_.php

Offline

 

#19 2012-03-16 14:36:03

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: A new XML file format for 2.0

You could also save parts of your project (like some sprites of scripts) in the exact same format just trimmed down to the bit you need.


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#20 2012-04-11 14:32:54

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: A new XML file format for 2.0

bump


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#21 2012-04-11 19:51:59

SJRCS_011
Scratcher
Registered: 2011-02-07
Posts: 1000+

Re: A new XML file format for 2.0

joefarebrother wrote:

SJRCS_011 wrote:

maybe for the scripts section we could use the block plugin syntax.

well how would you define c-blocks?

Then use an adapted version that is nonetheless the same or very similar to the syntax


http://i.imgur.com/vQqtH.png
Learning to Program in a Nutshell:  "You're missing a closing parentheses" - LS97

Offline

 

#22 2012-04-13 06:10:10

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: A new XML file format for 2.0

SJRCS_011 wrote:

joefarebrother wrote:

SJRCS_011 wrote:

maybe for the scripts section we could use the block plugin syntax.

well how would you define c-blocks?

Then use an adapted version that is nonetheless the same or very similar to the syntax

well my only issue is performance: if the scripts were in a different syntax to the rest, there will have to be extra code to parse this syntax and validate it, then write it back when something is saved, meaning it will take longer and scratch itself will need a larger file size. If the scripts were XML, all syntax errors will be caught by the XML parser and then the structure is quick and easy to navigate and therefore quick to load projects.


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

Board footer