Skip to content

Conversation

@tjvr
Copy link
Contributor

@tjvr tjvr commented Jan 30, 2017

Good morning! :)

This is a small PR to add a "stringify..." option to the menu. This opens a dialog box containing scratchblocks code, which can be copy/pasted into the Scratch Forums. (You can also try the test page, but since Snap! already has a "script pic" feature, the test page is less useful!)

Uploading pictures to the Snap! forums is quite time-consuming. Copy/pasting scratchblocks code is quicker, and might help to facilitate discussion on the User thread.

I've partly done this as an exercise in writing code in a Jens-approved style; please let me know what you think @jmoenig! :-)

@jmoenig
Copy link
Owner

jmoenig commented Jan 30, 2017

Thank you!!

I love this idea, it's wonderful to be able to convert Snap scripts into text-code that can then be pasted into the Scratch Forums. Did you know that one of my very first contributions to Scratch (way back when, I think it must have been v 1.2) was the ability to convert scripts to XML, and my example was always pasting blocks into the forums?

This looks quite pullable. Just one question: Would it be possible - and perhaps even make sense - to just use Snap's built-in "Codification" mechanism for this, instead of hard-coding the Scratch-Forum block syntax into the Snap sources? That way we could offer any kind of stringification, and externalize it, too. The only new feature we'd have to add would be to pop-up an alert-box letting you copy the generated code out of Snap.

Does that make sense at all?
Thanks!

@tjvr
Copy link
Contributor Author

tjvr commented Jan 30, 2017

I'm glad you like it! :-)

I thought about using codification to implement this, but I don't think it would make sense. Here's why: the scratchblocks syntax very closely mirrors the Morphic structure of the blocks. This PR is able to be so small because of this. It makes more sense to think about scratchblocks as an alternative "rendering" of the block morphs, than as a language that you can codify to! This means that I don't have to hard-code all of the blocks, in fact.

So while it's a neat idea, I don't think it would make sense to combine scratchblocks and codification. Unless codification works very differently than I thought!

Did you know that one of my very first contributions to Scratch (way back when, I think it must have been v 1.2) was the ability to convert scripts to XML

You know, I do remember that! It was called Chirp, wasn't it? :)

@jmoenig
Copy link
Owner

jmoenig commented Jan 30, 2017

Ah, okay, your explanation does make sense yes. Awesome, I'm going to pull this next up. Thank you so much!

@tjvr
Copy link
Contributor Author

tjvr commented Jan 30, 2017

Great! I'm very pleased :D Thanks Jens!

@BookOwl
Copy link

BookOwl commented Jan 30, 2017

@tjvr
Copy link
Contributor Author

tjvr commented Jan 30, 2017

thanks, fixed :)

blocks.js Outdated
menu.addItem(
'stringify...',
function() {
var code = myself.stringify();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, how about replacing this with a Morphic dialog box? Now that Morphic supports copy & paste of text, we can do this nicer :-)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make a generic one that has some text about how to copy and paste. C&P is only supported via keyboard shortcuts so it's non-obvious to many.

Anyway, there's a mostly correct dialog in #1084

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems like a lot of code just for copy/pasting scratchblocks!

If you don't mind I'm not going to do that here, and instead open a new issue for that improvement. :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's mostly just layout / morphic code.

And if we use it in 2 place, then we could create a CopySelectionDialogMorph and store it in widgets.js, so then it's like...no code. ;)

"delete",
'userDestroy'
);
menu.addItem(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the word "stringify" is confusing. Namely many Snap! users aren't familiar with the term "string", but also, in my mind at least "stringify" implies are more generic use than Scratch Blocks syntax.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That later comment also means I have reservations about using the function stringify for something like this, as opposed to say toScratchBlocks, which I think is much more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the best name, no! But has to be better than "scratchblocks"...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But has to be better than "scratchblocks"...

Wait, why? (or am I just missing something)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name "scratchblocks" is really unhelpful; to someone unfamiliar with the term, it doesn't really help explain what it is. Maybe "export text" or something? The closest analogy I can think of is the export project summary feature from Scratch 1.x...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess so, but "scratchblocks" is at least specific about what this is. If you google "scratchblocks" then your project at least comes up at the top so it's discoverable.

Also, since this is only for the Scratch forum (at the moment) we might just say "export for scratch forum" (and update it as needed in the future)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "as forum code"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forum code... is what I was thinking too!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forum code sounds good to me!

// SymbolMorph to "scratchblocks"

SymbolMorph.prototype.stringify = function () {
var symbol = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This format seems confusing to me, especially since there's only one option.

Why not just use a simple conditional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's mapping Snap! icon names to scratchblocks icon names. We might add more icons in the future, I guess.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get what it's doing, but only after reading it like a few times. That reason makes sense, though it seems better, to me, to add complexity as needed, that's all.

blocks.js Outdated

TemplateSlotMorph.prototype.stringify = function () {
var category = this.parent.stringifyCategory() || ' :: grey';
return '(' + this.children[0].stringify() + category + ')';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Snap, template variables are in doubled rings, like here: script variables ((a)::grey) ::grey

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already done! Please try the demo version

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your demo site either isn't updated to the newest code, or your code is still buggy, because I'm still getting incorrect results for rings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still getting incorrect results for rings

What specific examples don't work?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, it's working now.

@tjvr
Copy link
Contributor Author

tjvr commented Jan 31, 2017

Okay, I've renamed the methods & the menu item. :)

I opened #1648 for the dialog enhancement.

Other than that this should be ready to merge :)

@cycomachead
Copy link
Collaborator

LGTM. (At least the code, I haven't had a chance to test it yet)

blocks.js Outdated

SyntaxElementMorph.prototype.toScratchblocksCategory = function () {
// private. answers with scratchblocks category specifier
if (!this.category) return '';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Jens uses {return ''; } as the format of these things.

blocks.js Outdated
'userDestroy'
);
menu.addItem(
'forum code...',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: space between n and (

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I vote for "Scratchblocks" over "forum code." It really is quite Scratch-specific. When we have our own forum with Snap!blocks we can change the item name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to scratchblocks code.... :)

@cycomachead
Copy link
Collaborator

I vote for "Scratchblocks" over "forum code." It really is quite Scratch-specific. When we have our own forum with Snap!blocks we can change the item name.

Speaking of which we should get on that. Remind me to bring this up next week!

@jmoenig
Copy link
Owner

jmoenig commented Jul 28, 2017

I've changed my mind about this, nice as it is. Basically, we will get another way to export scripts in our own format. For this we might make a forum plug-in that renders the exported scripts. But then we can also drag thoses shared scripts back into Snap, and use them as "real" ones. We need to ponder this some more....

@tjvr
Copy link
Contributor Author

tjvr commented Jul 28, 2017

Fair enough :-) Feel free to close!

@brianharvey
Copy link
Collaborator

If the alleged our-own script-to-text format is > 1/2 year away, I would still argue for pulling this in the coming release.

@jmoenig
Copy link
Owner

jmoenig commented Jul 30, 2017

The format is mostly done, it's @bromagosa's PR #1746

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants