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

#5901 2012-08-28 10:06:58

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: BYOB 3 - Discussion Thread

@Jens, for exporting projects, use:

Code:

if (!window.URL) {
    window.URL = window.webkitURL;
}

...

var data = <insert project data here>;
var fileName = <insert project name here>;

var bytes = new Uint8Array(data.length);

for (var i = 0; i < data.length; i++) {
    bytes[i] = data.charCodeAt(i);
}

var url = URL.createObjectURL(new Blob([bytes]));

var a = document.createElement('a');
a.href = url;
a.download = fileName;
a.type = 'application/zip';
a.onclick = function () {
    setTimeout(function () {
        URL.revokeObjectURL(url)
    }, 20);
}
a.click();

Last edited by MathWizz (2012-08-28 10:25:08)


http://block.site90.net/scratch.mit/text.php?size=30&amp;text=%20A%20signature!&amp;color=333333

Offline

 

#5902 2012-08-28 11:46:49

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

Re: BYOB 3 - Discussion Thread

bharvey wrote:

MathWizz wrote:

Question... Why did you go with XML instead of JSON?

We actually went back and forth on this, but afaik there's no terribly compelling reason either way.  It's just aesthetic taste.  Do you think differently?

As others have pointed out, it's smaller and easier to parse. Why did you go with XML...?  tongue


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

Offline

 

#5903 2012-08-28 12:04:19

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: BYOB 3 - Discussion Thread

MathWizz wrote:

Question... Why did you go with XML instead of JSON?

I chose it for a couple of reasons:
- The distinction between attributes and children makes a lot of features in a project's serialized form concise, e.g. blocks (<block s="selector">arguments…</block> vs { "type": "block", "s": "selector", "arguments": [ arguments… ] } or something similar) and expressions
- The implicit "type" (an element's tag name) makes a few things simpler (e.g. loading blocks) and makes a bunch of things shorter (e.g. <type id="id" …/> vs { "type": "type", "id": "id"… } and <ref id="id"/> vs { "type": "ref", "id": "id" })
- Fewer quotation marks   tongue

Last edited by nXIII (2012-08-28 12:06:06)


nXIII

Offline

 

#5904 2012-08-28 12:18:22

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: BYOB 3 - Discussion Thread

How about the fact that Scratch 2.0 is in JSON? Not only does it mean someone probably thought it through at MIT, is also means we can compile 2.0 to Snap! (and maybe vice-versa in a future Scratch release).


Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#5905 2012-08-28 12:25:49

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Hardmath123 wrote:

How about the fact that Scratch 2.0 is in JSON? Not only does it mean someone probably thought it through at MIT, is also means we can compile 2.0 to Snap! (and maybe vice-versa in a future Scratch release).

The formats wouldn't be identical so we'd have to import/export anyway.

Last edited by nXIII (2012-08-28 12:30:27)


nXIII

Offline

 

#5906 2012-08-28 13:28:37

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: BYOB 3 - Discussion Thread

to me an imortant benefit of XML is that it's human readable and "open" in an almost natural way, i.e. it can be understood by itself and others can easily create apps which read / write it. For example, some institutions want to evaluate students' projects in a textual form, and we can just point them to our XML format, which actually *is* a textual form. Same for people with disabilities, they can probably use an XML format much better than a cryptic JSON one. But, most important to me, our XML projects can be inspected (and edited!) in the browser and in any text editor, even without JS.


Jens Mönig

Offline

 

#5907 2012-08-28 13:38:41

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Jens... Did you see this?

MathWizz wrote:

@Jens, for exporting projects, use:

Code:

if (!window.URL) {
    window.URL = window.webkitURL;
}

...

var data = <insert project data here>;
var fileName = <insert project name here>;

var bytes = new Uint8Array(data.length);

for (var i = 0; i < data.length; i++) {
    bytes[i] = data.charCodeAt(i);
}

var url = URL.createObjectURL(new Blob([bytes]));

var a = document.createElement('a');
a.href = url;
a.download = fileName;
a.type = 'application/zip';
a.onclick = function () {
    setTimeout(function () {
        URL.revokeObjectURL(url)
    }, 20);
}
a.click();

http://block.site90.net/scratch.mit/text.php?size=30&amp;text=%20A%20signature!&amp;color=333333

Offline

 

#5908 2012-08-28 14:05:38

iTweak0r
Scratcher
Registered: 2011-07-30
Posts: 100+

Re: BYOB 3 - Discussion Thread

I like your snap thing (It is a really cool thing, byob in the browser or on the tablet ['cause usually web apps are flash])

but here is a bug: when i import a sound in snap then play it, it takes a while to start and really lags the game.

a thing I want: a paint editor!


Make it in Scratch! because it's cooler when it's made in scratch
http://i.imgur.com/D4iqPHR.png

Offline

 

#5909 2012-08-28 14:07:24

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Jens wrote:

to me an imortant benefit of XML is that it's human readable and "open" in an almost natural way, i.e. it can be understood by itself and others can easily create apps which read / write it. For example, some institutions want to evaluate students' projects in a textual form, and we can just point them to our XML format, which actually *is* a textual form. Same for people with disabilities, they can probably use an XML format much better than a cryptic JSON one. But, most important to me, our XML projects can be inspected (and edited!) in the browser and in any text editor, even without JS.

I don't find JSON any less readable than XML, if it's properly formatted (it just looks like a JS object literal with way too many quotation marks); if it's not, I agree that it's even worse than whitespace-stripped XML.

Also, you can edit JSON in any text editor (or the browser, with <textarea> and friends). You don't need JS for anything except parsing it (but you can use other things to parse it, too).



I was trying to name variables with Unicode characters in Snap and realized I couldn't (via copy-paste, Character Viewer, or an option-keypress), so I made a script that replaces Morphic.js's CursorMorph-based text editors with native ones. This adds support for all platform-specific input methods and keyboard shortcuts as well as copy-paste and undo. You can install it in your local copy of Snap by adding the following line:

Code:

<script src=http://dl.dropbox.com/u/10715865/Web/Snap/inject/native-editors.js></script>

Or use the following bookmarklet to use it on the hosted copy:

Code:

javascript:var d=document,s=d.createElement('script');s.src='http://dl.dropbox.com/u/10715865/Web/Snap/inject/native-editors.js';d.querySelector('head').appendChild(s)

Last edited by nXIII (2012-08-28 14:46:19)


nXIII

Offline

 

#5910 2012-08-28 19:36:49

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

nXIII wrote:

This adds support for all platform-specific input methods and keyboard shortcuts as well as copy-paste and undo.

Ah, that's interesting.  How do I install it on my Android tablet?  And will it solve the problem of the virtual keyboard not appearing?


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#5911 2012-08-28 20:14:18

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

Ah, that's interesting.  How do I install it on my Android tablet?  And will it solve the problem of the virtual keyboard not appearing?

I'm not sure how you can install it (unless you use a local server and navigate to a local copy on your desktop).

It probably would fix the virtual keyboard not appearing, but I haven't tested it so I'm not sure.


nXIII

Offline

 

#5912 2012-08-28 21:25:42

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

nXIII wrote:

I'm not sure ...

I'm at work and the tablet is at home, so stay tuned.  smile


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#5913 2012-08-29 04:33:14

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

Re: BYOB 3 - Discussion Thread

OK, my non-determinism project works partially now.  The sprite says the first choice but then for some reason it (seems to) get stuck in an infinite loop (the script is still highlighted but it isn't doing anything). That is still better than it not working at all and just red-haloing the script with no indication of what went wrong. However, now it won't save.  sad

Screenshot:
http://oi48.tinypic.com/d8zg9.jpg
PS: the input for choose is varadic, any unevaluated.

So two things: Why does it get stuck, and why won't it save?

EDIT: Now it doesn't get stuck any more, but, weirdly, it sometimes says 3 then fail, and sometimes it says 3 then 4 then causes an error. None of these were the intended behaviour, which is to say 3, then 4, then 5, then fail. It still won't save, either.

Last edited by joefarebrother (2012-08-29 07:14:52)


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

 

#5914 2012-08-29 07:36:10

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: BYOB 3 - Discussion Thread

nXIII wrote:

... I made a script that replaces Morphic.js's CursorMorph-based text editors with native ones.

Isn't this pretty much what current versions of Morphic.js already do with what I call "virtual keyboard" support? Create a HTML input element, make it transparent and relay its events to the Morphic Cursor? So we really just have to add maybe two more event bindings to the existing code to get copy/paste for free, right?


Jens Mönig

Offline

 

#5915 2012-08-29 07:42:20

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: BYOB 3 - Discussion Thread

joefarebrother wrote:

...the input for choose is varadic, any unevaluated.
... causes an error ...

hmm., I've never even tried variadic unevaluated inputs in Snap. Maybe they plain don't work yet  smile  did you try them on something simpler?


Jens Mönig

Offline

 

#5916 2012-08-29 07:55:19

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

Re: BYOB 3 - Discussion Thread

Jens wrote:

did you try them on something simpler?

Yeah... it didn't work for plain "any" inputs either. Same result: 3, 4, error.

Maybe it's a bug with continuations being stored in variables and being called more than once?


What!?
When I try to save,

snap! wrote:

"Save failed: TypeError: Object 4 has no method "toXML"

So now I can't put numbers in my project?????

Last edited by joefarebrother (2012-08-29 08:02:43)


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

 

#5917 2012-08-29 08:08:51

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Well, hunting bugs means trying to spot exactly where something doesn't produce an expected result, and finding the *first* place where this happens, so we'll have to try something *simpler* not the same complex mashup with one single thing changed...

Let's try to get out of this abbreviated alarm mode and do some engineering here ... once I get back from my vacation  smile


Jens Mönig

Offline

 

#5918 2012-08-29 12:59:59

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

Re: BYOB 3 - Discussion Thread

Oh, Ok.

Well, i did a few tests with continuations and varadic unevaluated slots (the two suspects of the bug) and I found that it is an error to find the continuation of a block that is at the bottom of the script, when it shouldn't be an error to do so. It should report a "default" continuation which does nothing, like stop block if it is the continuation of a command, or report if it is the continuation of a reporter. That was the only bug i found, though, and it doesn't help me solve my problem.


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

 

#5919 2012-08-29 14:11:51

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Jens wrote:

Isn't this pretty much what current versions of Morphic.js already do with what I call "virtual keyboard" support? Create a HTML input element, make it transparent and relay its events to the Morphic Cursor? So we really just have to add maybe two more event bindings to the existing code to get copy/paste for free, right?

Nope. This one overlays the text editor so selection and editing are managed by the native <input>, which allows access to all platform features like:

- Correct key bindings (alt/ctrl/cmd+arrows on mac, selection with shift)
- Copy & paste (support for this isn't very good with JS events)
- Spellchecking
- Services, Look Up, Search, & Speech (OS X)
- Undo/Redo


nXIII

Offline

 

#5920 2012-08-29 15:41:33

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

Re: BYOB 3 - Discussion Thread

nXIII wrote:

This one overlays the text editor so selection and editing are managed by the native <input>, which allows access to all platform features like: ...

Oh, awesome! I've been wishing you'd do this for a while...  big_smile


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

Offline

 

#5921 2012-08-29 19:29:13

Lucario621
Community Moderator
Registered: 2007-10-03
Posts: 1000+

Re: BYOB 3 - Discussion Thread

I'm not sure if anybody has posted about this yet (sorry if it already has), but recently I just noticed this video about Snap! I thought it was pretty interesting - I'm looking foward to see how Snap! will do with supporting real world sensors and such.  smile


http://i.imgur.com/WBkM2QQ.png

Offline

 

#5922 2012-08-30 00:39:56

bharvey
Scratcher
Registered: 2008-08-10
Posts: 1000+

Re: BYOB 3 - Discussion Thread

Lucario621 wrote:

this video about Snap!

The most interesting part to me was the wrong-color (not zebraed) second WAIT block.  smile   But he was working from an old version of Snap! (not super old of course) so maybe that bug is already fixed.  (fingers crossed)


http://cs.berkeley.edu/~bh/sig5.png

Offline

 

#5923 2012-08-30 07:13:30

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: BYOB 3 - Discussion Thread

... fixed!


Jens Mönig

Offline

 

#5924 2012-08-30 07:21:51

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

Re: BYOB 3 - Discussion Thread

Whats fixed?


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

 

#5925 2012-08-30 08:02:09

Jens
Scratcher
Registered: 2007-06-04
Posts: 1000+

Re: BYOB 3 - Discussion Thread

the zebra coloring bug in the video (and a few other minor ones, including the script-variable one that's been reported by you)


Jens Mönig

Offline

 

Board footer