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

#4551 2012-02-12 15:35:26

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

Re: BYOB 3 - Discussion Thread

bharvey wrote:

scimonster wrote:

AJAX+JS+PHP.

Does it have to be that complicated?  I'm pretty sure there were download buttons on web pages before there was Ajax.

Yeah, you can just redirect the browser to a URL that it would normally download (or one where you've set the content-disposition in the header). However, that requires PHP, which defeats the purpose of allowing Snap to run offline.

What you can do (what I was talking about above) is use a data: URL. The problem is, browsers don't know the filename and substitute fairly awful things. Firefox uses a (seemingly random) filename that ends in ".part" and Safari just uses "Unknown". I got around this by creating an "a" element and setting its 'download' attribute to the filename. Then, I created and dispatched a mouse event on the anchor (so the user doesn't have to click it). In all browsers, this downloads the file as something, but only Chrome pays attention to the 'download' attribute; the rest of the browsers just use the filenames described above.

Last edited by nXIII (2012-02-12 15:36:24)


nXIII

Offline

 

#4552 2012-02-12 16:30:12

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

scimonster wrote:

AJAX+JS+PHP.

Does it have to be that complicated?  I'm pretty sure there were download buttons on web pages before there was Ajax.

you could just have a php page that you send the information for the file as a post header, the php file could then spit out a text file (or whatever) using PHP Headers

edit: that page isn't helpful at all, let me find another.

edit2: try this one
Basically, you put something like this in a php page:

Code:

<?php
header('Content-Type: application/octet-stream'); //octet stream is the download mime type.
header('Content-Disposition: attachment; filename="example.txt"'); //specifies the filename that the user will download and how it will be accessed (use attachment basically)
header('Content-Transfer-Encoding: 8bit'); //whether the file is binary or other types such as 8-bit and base 64.
echo('contents of whatever you want example.txt to be')
?>

There is more stuff you can do such as caching, but you won't really need to do that as the output is going to be pretty dynamic.

Last edited by rookwood101 (2012-02-12 16:39:39)


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

Offline

 

#4553 2012-02-12 16:38:16

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

Re: BYOB 3 - Discussion Thread

nXIII wrote:

Firefox uses a (seemingly random) filename that ends in ".part"

I've seen those ".part" files, but for me, once the download is complete the file is renamed to whatever name I gave in the file dialog.  (When I download a file from cnet or someplace like that, I don't even have to give a filename; it just works.  But for saving projects, we want the user to give a name, at least the first time.)

I'd be happy with PHP on the snap.berkeley.edu site, if that'll let users click on a SAVE button without having any extra software on their own computer.


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

Offline

 

#4554 2012-02-12 16:55:23

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

Re: BYOB 3 - Discussion Thread

rookwood101 wrote:

you could just have a php page that you send the information for the file as a post header...

Awesome, write it and send Jens a changeset.  (Don't post it here, send it to jens atsign moenig.org)  The goal is that when you click on "save as" or when you click on "save" and the project doesn't have a name, it puts up a file browser or a morphic dialog, whatever works, to get the project name, then calls nXIII's serialization code and downloads the result into project.snap.  And if you click on "save" and the project does have a name, it uses that.

Last edited by bharvey (2012-02-12 16:56:32)


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

Offline

 

#4555 2012-02-12 17:43:39

rookwood101
Scratcher
Registered: 2011-07-29
Posts: 500+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

rookwood101 wrote:

you could just have a php page that you send the information for the file as a post header...

Awesome, write it and send Jens a changeset.  (Don't post it here, send it to jens atsign moenig.org)  The goal is that when you click on "save as" or when you click on "save" and the project doesn't have a name, it puts up a file browser or a morphic dialog, whatever works, to get the project name, then calls nXIII's serialization code and downloads the result into project.snap.  And if you click on "save" and the project does have a name, it uses that.

I think one of you guys are probably best off doing it. My JavaScript skills are nowhere near as advanced as your's, Jens' or nXIII's and it would probably take me several days just to work out where to put everything and which function does what etc.  smile

And I'm sure you can set up the php page to do that (if not I will) and also I'm sure you can send post headers to pages from within javascript. I quite like hanging around on this thread because I'm interested to see what you guys are doing, but I'm not at the level of actually being able to do anything yet  smile


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

Offline

 

#4556 2012-02-12 20:12:58

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

Re: BYOB 3 - Discussion Thread

rookwood101 wrote:

I think one of you guys are probably best off doing it.

OK, n, that's your cue.  smile


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

Offline

 

#4557 2012-02-12 20:35:31

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

Re: BYOB 3 - Discussion Thread

bharvey wrote:

rookwood101 wrote:

I think one of you guys are probably best off doing it.

OK, n, that's your cue.  smile

I think we should work on a host for uploading projects that can be set up by schools, etc. instead of just making a file download mirror (which is the same as clicking "Share..." and saving the resulting text file). I can start to work on that after I finish the project importer (which, by the way, now works for all Scratch projects!  big_smile )


nXIII

Offline

 

#4558 2012-02-12 21:12:40

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

Re: BYOB 3 - Discussion Thread

Fixed a bug in XMLSerializer—custom blocks which use later-defined custom blocks in their definitions now load correctly.

Last edited by nXIII (2012-02-12 21:12:50)


nXIII

Offline

 

#4559 2012-02-12 21:30:23

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

Re: BYOB 3 - Discussion Thread

Bug: the mod block is incorrect; it uses JS's % operator, which returns a number with the sign of its dividend, not its divisor like the BYOB mod block. For example, (-4 mod 3) should return 2, and (4 mod -3) should return -2.


nXIII

Offline

 

#4560 2012-02-13 04:48:52

xly
Scratcher
Registered: 2010-04-17
Posts: 100+

Re: BYOB 3 - Discussion Thread

@nXII
Import from a simple Scratch project is starting to work.
Then this projcst can be correctly Saved, but once Saved it is not possible to re-Open it after.

Offline

 

#4561 2012-02-13 05:50:37

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

Re: BYOB 3 - Discussion Thread

Maybe it could use PHP to save the xml file on the internet and it will give you a unique project ID that you could use to open the project later.


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

 

#4562 2012-02-13 10:03:42

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Re: BYOB 3 - Discussion Thread

I just managed to make a forever-looping block-- it was atomic too, so if you make an atomic block run forever BYOB crashes... any way to fix this?

Offline

 

#4563 2012-02-13 10:16:17

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

Re: BYOB 3 - Discussion Thread

rdococ wrote:

I just managed to make a forever-looping block-- it was atomic too, so if you make an atomic block run forever BYOB crashes... any way to fix this?

In BYOB 3 you can click the stop sign (may need to hold for a second or two).  We don't have a stop sign in Snap! yet, but it's coming.  Maybe you can stop your script by clicking on it again.

Last edited by bharvey (2012-02-13 10:16:54)


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

Offline

 

#4564 2012-02-13 11:24:30

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

Re: BYOB 3 - Discussion Thread

what's actually bad in this?
http://www.webmasterworld.com/forum91/3463.htm
just make it download a Snap! URI  smile

Offline

 

#4565 2012-02-13 11:35:35

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

rdococ wrote:

I just managed to make a forever-looping block-- it was atomic too, so if you make an atomic block run forever BYOB crashes... any way to fix this?

In BYOB 3 you can click the stop sign (may need to hold for a second or two).  We don't have a stop sign in Snap! yet, but it's coming.  Maybe you can stop your script by clicking on it again.

No, it was atomic, so Squeak wouldn't respond. I couldn't even change block categories or click anything.

Offline

 

#4566 2012-02-13 11:54:50

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

Re: BYOB 3 - Discussion Thread

rdococ wrote:

No, it was atomic, so Squeak wouldn't respond. I couldn't even change block categories or click anything.

Yes you can, you can click the stop sign.  You may have to hold it down for a couple of seconds.


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

Offline

 

#4567 2012-02-13 11:58:31

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

Re: BYOB 3 - Discussion Thread

roijac wrote:

what's actually bad in this?
http://www.webmasterworld.com/forum91/3463.htm
just make it download a Snap! URI  smile

That has to be a whole separate page, I think.  We want to stay on the Snap! page after the save is complete.


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

Offline

 

#4568 2012-02-13 12:00:38

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

Re: BYOB 3 - Discussion Thread

joefarebrother wrote:

Maybe it could use PHP to save the xml file on the internet and it will give you a unique project ID that you could use to open the project later.

One of my colleagues suggested that unique-ID idea, but the user shouldn't have to remember a string of gibberish to retrieve the project later.  It should be saved under the user-supplied name, or maybe something like userid_projectname.


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

Offline

 

#4569 2012-02-13 16:54:20

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

Re: BYOB 3 - Discussion Thread

bharvey wrote:

rdococ wrote:

No, it was atomic, so Squeak wouldn't respond. I couldn't even change block categories or click anything.

Yes you can, you can click the stop sign.  You may have to hold it down for a couple of seconds.

i think you have to hold escape


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

 

#4570 2012-02-13 16:57:46

rdococ
Scratcher
Registered: 2009-10-11
Posts: 1000+

Re: BYOB 3 - Discussion Thread

bharvey wrote:

rdococ wrote:

No, it was atomic, so Squeak wouldn't respond. I couldn't even change block categories or click anything.

Yes you can, you can click the stop sign.  You may have to hold it down for a couple of seconds.

Actually, I tried that when I accidentally put a small condition in to replace a really big condition, and I held the stop sign and it worked!

Offline

 

#4571 2012-02-13 18:41:44

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

Re: BYOB 3 - Discussion Thread

Another (fairly serious) bug: custom blocks don't show up in the palette when a project is opened. This is because the 'sprite' variable is closed into the action of each palette button, so it uses the old sprite to populate the palette.


nXIII

Offline

 

#4572 2012-02-13 22:40:12

BornAgainAtheist
New Scratcher
Registered: 2012-02-13
Posts: 42

Re: BYOB 3 - Discussion Thread

Hi guys, its 14God, I decided to get a new profile to celebrate *&$*#^$^@*$*&#^@*$^$%# (censored for political correctness  tongue  )

Offline

 

#4573 2012-02-13 23:21:34

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

Re: BYOB 3 - Discussion Thread

BornAgainAtheist wrote:

I decided to get a new profile

... and we get your first post!  Honored.


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

Offline

 

#4574 2012-02-13 23:23:21

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

Re: BYOB 3 - Discussion Thread

joefarebrother wrote:

i think you have to hold escape

That was true a couple of years ago, but not any more.  As I said, if you're running an atomic script you may have to hold down the stop sign a second or so before BYOB notices, but it should always work.


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

Offline

 

#4575 2012-02-14 10:52:03

sci_test
Scratcher
Registered: 2011-06-22
Posts: 100+

Re: BYOB 3 - Discussion Thread

Google Sites somehow is able to force the browser to download the file. They do that when you add ?d=1 at the end of an attachment URL. Without it, if it's an image or other browser-readable attachment, it doesn't download. Anyone know how to do that?


[signature removed - please be respectful]
Last edited by scimonster (1970-01-01 00:00:00)

Offline

 

Board footer