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

#1 2012-08-25 07:37:29

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

Scratch source: ScriptableScratchMorph blockWithID:a

Good afternoon, ATs! Can any of you Squeak people figure out how to reverse-engineer this method in Python?

ScriptableScratchMorph blockWithID:

A little context:

As I've mentioned countless times on here, I'm working on reverse-engineering Scratch files in Python, and converting that to & from text/images/sound files (which I've nearly finished). (Loads of people have requested text-based Scratch, so hopefully someone will want to use it...)

What I can't figure out is how to do comments. Here's what I know:

* comments are stored as separate scripts — even when they're attached to a block.
* they're stored at the end of the blocksBin array.
* they have the form (#scratchComment, showing, width, anchor). anchor is optional, and is the "block ID" of the block the comment's attached to. It's resolved to a block object using the blockWithID: method I mentioned.
(refer to blockFromTuple:receiver: to correct me on this.)

I can vaguely read Squeak code, enough to get this far; but I cannot work out how to reverse-engineer the block ID in Python. Simply taking the nth block on the sprite doesn't seem to work. It even seems to change every time you save the file!

If you could give me any ideas, I'd be humbly indebted to you. Thanks! (:

(Alternatively, if I'm just being stupid, feel free to point that out too...)


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

Offline

 

#2 2012-08-25 08:21:30

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

Re: Scratch source: ScriptableScratchMorph blockWithID:a

I believe it changes based on last drag/dropped block. That's how broadcast-activated hats get prioritized, too. So for example, if I had two scripts beginning with a "die" event listener, the last dragged will be executed first.  smile


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

Offline

 

#3 2012-08-25 08:38:22

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

Re: Scratch source: ScriptableScratchMorph blockWithID:a

Good thought, thanks!  smile  That fits what I'm seeing. I think more recently dragged scripts appear at the top of the blocksBin array.

But still, any idea how to determine that from the tuples saved on blocksBin?


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

Offline

 

#4 2012-08-25 08:59:20

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

Re: Scratch source: ScriptableScratchMorph blockWithID:a

It seems to be reversed somehow... With a single script of 4 blocks, and a comment on the first, the ID is 4. (I keep forgetting Squeak arrays are 1-based...)


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

Offline

 

#5 2012-08-25 09:23:02

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

Re: Scratch source: ScriptableScratchMorph blockWithID:a

I played with a load of examples, and I think I've finally figured it out: the order of the blocks in the scripts are reversed, but not the list of scripts. The idea to focus on last dragged was a good one, and helped me spot the pattern. Thanks, HardMath!

Now to figure out how C-blocks affect the ID...


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

Offline

 

#6 2012-08-25 09:27:00

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

Re: Scratch source: ScriptableScratchMorph blockWithID:a

...and hats.


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

Offline

 

#7 2012-08-25 09:58:43

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

Re: Scratch source: ScriptableScratchMorph blockWithID:a

Hats are just blocks, it turns out. The thing works!  big_smile


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

Offline

 

#8 2012-08-25 11:08:41

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

Re: Scratch source: ScriptableScratchMorph blockWithID:a

Congratulations! Glad I could help.  smile


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

Offline

 

Board footer