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...)
Offline
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.
Offline
Good thought, thanks!
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?
Offline
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...)
Offline
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...
Offline
...and hats.
Offline
Hats are just blocks, it turns out. The thing works!
Offline
Congratulations! Glad I could help.
Offline