Discuss Scratch

NoMod-Programming
Scratcher
1000+ posts

SQUEAK HELP

Please help! I have been developing a Scratch 1.4 mod that adds a backpack area like Dream's. I have successfully implemented everything, including reopening the backpack after quitting my mod, but am stuck at a very important part! When importing a block from the “backpack.tps” file, if the block contains a color value, it is converted to nil. The backpack.tps file is the file used to backup the backpack for later use.

Contents of the Backpack File wrote:

(((#EventHatMorph ‘Scratch-StartClicked’) (#putPenDown) (#penColor: (#Color #r: 0.86 #g: 0.584 #b: 0.19)) (#penSize: 5) (#doForever ((#forward: 10) (#bounceOffEdge)))))
Here is the script I am running to get the contents of the file: (In ScriptableScratchMorph)
readFile: t1
| t2 t3 |
(FileDirectory default fileExists: t1)
ifFalse: [^ ''].
t2 _ (FileStream readOnlyFileNamed: t1) binary.
t2 ifNil: [^ ''].
t3 _ t2 contentsOfEntireFile asString.
t2 close.
^ t3
and the code I am using to convert them to a usable format: (In ScratchStageMorph:Initialize)
commonScripts _ ((((self readFile: 'backpack.tps') asString) size = 0) ifTrue: [OrderedCollection new] ifFalse: [(Compiler evaluate: ('#',(self readFile: 'backpack.tps')) for: self logged: false)]).

Here is the code I use for converting the “Commonscripts” variable to blocks: (In ScriptableScratchMorph)
viewerPageForScripts
| t1 t2 t3 t4 t5 t6 t7 |
t1 _ ScratchBlockPaletteMorph new.
(self isKindOf: ScratchStageMorph)
ifTrue: [t2 _ self commonScripts isEmpty]
ifFalse:
[t2 _ self commonScripts isEmpty.
t3 _ self ownerThatIsA: ScratchStageMorph].
t2
ifTrue:
[t4 _ ScratchFrameMorph getFont: #ViewerPage.
t5 _ 20.
t6 _ 12.
t7 _ StringMorph contents: 'Drag frequently used scripts' localized font: t4.
t1 addMorph: (t7 color: Color white;
position: t5 @ t6).
t7 _ StringMorph contents: 'here for easier access' localized font: t4.
t1 addMorph: (t7 color: Color white;
position: t5 @ (t6 + 17)).
^ t1].
t5 _ 15.
t6 _ 10.
self commonScripts do: [:t8 | t8 = #- | (t8 = #~)
ifTrue:
[t8 = #- ifTrue: [t6 _ t6 + 15].
t8 = #~ ifTrue: [t6 _ t6 + 5]]
ifFalse: [t6 _ self
createBlock: (self stackFromTupleList: t8 receiver: self)
atPosition: t5 @ t6
onPage: t1]].
^ t1
SOME CREDITS GO TO DREAM AND EXPLORE, both by their respective owners

Long-since moved on from Scratch, if you need to find all my posts, search this in google: 3499447a51c01fc4dc1e8c3b8182b41cb0e88c67

Powered by DjangoBB

Standard | Mobile