Hmm. I'll have another good look and get back to you.
Through some other ways of testing, I have discovered the block is being made/created/programed wrong. Still trying to find the source of the problem.
Almost got it...
Its not your block declaring its something about the new tab thats wrong.
Weird new thing discovered. If you remove the block then recreate it (edit>undelete) it is the same block - but it works.
Oh, you never answered. How are you so good at Squeak?
Last edited by johnnydean1 (2011-05-21 04:49:25)
Offline
Open Scratch, inspect the hat block, and type this in the bottom workspace:
(self scriptOwner) privateOwner: ((World findA: ScratchFrameMorph) findA: ScratchStageMorph).
This sets the scriptOwner (a ScratchSpriteMorph) owner to the instance of the Stage that opens with Scratch. After this, the block works.
I tried to do something similar in ScriptableScratchMorph>>initialize and ScratchStageMorph>>initialize, but the VM stopped responding and I had to kill it.
Offline
Double-clicking the block doesn't work either because it calls BlockMorph>>doubleClick: which calls BlockMorph>>toggleProcess, which calls HatBlockMorph>>start and this one runs the same verification as EventHatMorph>>startForEvent:
(stage _ self receiver ownerThatIsA: ScratchStageMorph) ifNil: [^ self].
Which returns nil.
Offline
After a few days without looking at this, I've come up with a solution (which I had already thought of). In ScratchScriptEditorMorph>>currentCategory: method I added the following line of code in the if clause that tests if the actual tab is my new tab:
currentCategory = 'Teste' ifTrue: [
pageViewerMorph contents: self target testeBlocksBin.
((self target testeBlocksBin) findA: EventHatMorph) newScriptOwner: self target].After stating what was happening when I set up the scriptOwner's owner in the block inspector (see my post #29 on this topic), I realized that the only solution (at least one that works) was to do that somewhere in the source code. So I thought of doing that in the method fired by the tab changing, which is ScratchScriptEditorMorph>>categoryChanged:, which calls the aforementioned method of the same class.
So what the new line of code does is to find the ScratchScriptsMorph of the new tab (self target testeBlocksBin), and then find a submorph which is an EventHatMorph, which will return my hat block. After having the reference to that block, I only had to set its scriptOwner by calling the method BlockMorph>>newScriptOwner (inherited by means of subclassing) and passing it the scratch object responsible for owning the script (the ScriptableScratchMorph which, somehow, it's correctly linked to the stage). I found the newScriptOwner method by looking at the ScratchFrameMorph>>undoTool code, thanks to the tip provided by johnnydean1 (thank you for the help).
Gotta move on now!
Offline
Cool. If you read this can you make a image with all these specs so I can see the final code.
Good Luck in the future...
JD1
Offline
johnnydean1 wrote:
Cool. If you read this can you make a image with all these specs so I can see the final code.
Just add this change to the image I provided earlier and it should do it.
johnnydean1 wrote:
Good Luck in the future...
Thank you.
Offline