I'm having some problems with Dictionaries.
first of all, i saw that arrays are only up to 6 entries right? but never mind about that.
i'm working on Atom, a part of the Scratch UG project, and i'm making a BYOB/CYOB style thing (not copied at all though) where the user can code their own blocks just as if they were real hacked blocks.
i have two buttons: make a block and delete a block.
the make button works perfectly: it brings up a dialog (which i made) asking for the block spec and its code, in a textbox ad scrolling string respectively. the block then appears under the buttons.
the delete button doesn't work so great.
i click on it, that brings up a menu (which i coded) with all of the block specs for the custom blocks. all fine until now. if i don't select anything it just disappears (that's meant to be), but if i select an option, it brings up the debugger with an error. the ususal message not understood. here's my code:
copyright 2010 LS97 wrote:
deleteCustomBlock
| t1 t2 t3 |
customBlocks isNil ifTrue: [^ self beep].
t1 _ CustomMenu new.
t3 _ 1.
customBlocks size
timesRepeat:
[t1 add: ((customBlocks at: t3)
at: 2) asString action: t3.
t3 _ t3 + 1].
t2 _ t1 invokeOn: self defaultSelection: nil.
t2 = nil ifTrue: [^ self beep].
customBlocks removeKey: t2 asNumber
the error bit is the invoking it seems...
please help i'm stuck.
Offline
BUMP! pleaaseeeeeeeeeee!!!!!!!!!
Offline
Sorry dont do arrays
Offline
Unless its the double ':' as you have 2 meathods.
Offline
no that's fine
it's an error to do with the numbers probably!
please someone help! it's making me mad!
Offline
bump
Offline
Have you had a look at how the 'delete list' and 'delete variable' function works? perhaps that might help. Probaly not but just a thought. Oh and by the way if you can't do it it doesn't really matter! I also thinks it's fab what you've done with the add a custom block. It will be much better than opening the browser and will incourage others to start making there own blocks because it's in a nice and tidy enviroment.
Good Job.
Offline
yeah i'll have a look at that. it's vaguely similar, because those collections only have one level whilst i have this kind of tree:
Dictionary
Array
Array
Array
Array
Array
Array
and so on...
but anyway yah i don't know why i didn't think about that before
Last edited by LS97 (2010-08-12 12:19:07)
Offline
it didn't work.
Offline
LS97 wrote:
I'm having some problems with Dictionaries.
first of all, i saw that arrays are only up to 6 entries right? but never mind about that.
i'm working on Atom, a part of the Scratch UG project, and i'm making a BYOB/CYOB style thing (not copied at all though) where the user can code their own blocks just as if they were real hacked blocks.
i have two buttons: make a block and delete a block.
the make button works perfectly: it brings up a dialog (which i made) asking for the block spec and its code, in a textbox ad scrolling string respectively. the block then appears under the buttons.
the delete button doesn't work so great.
i click on it, that brings up a menu (which i coded) with all of the block specs for the custom blocks. all fine until now. if i don't select anything it just disappears (that's meant to be), but if i select an option, it brings up the debugger with an error. the ususal message not understood. here's my code:copyright 2010 LS97 wrote:
deleteCustomBlock
| t1 t2 t3 |
customBlocks isNil ifTrue: [^ self beep].
t1 _ CustomMenu new.
t3 _ 1.
customBlocks size
timesRepeat:
[t1 add: ((customBlocks at: t3)
at: 2) asString action: t3.
t3 _ t3 + 1].
t2 _ t1 invokeOn: self defaultSelection: nil.
t2 = nil ifTrue: [^ self beep].
customBlocks removeKey: t2 asNumberthe error bit is the invoking it seems...
please help i'm stuck.
Here:
© 2010 nXIII (but it's not registered so you can steal it
) wrote:
deleteCustomBlock
| menu choice |
customBlocks isNil ifTrue: [^ self beep].
menu := CustomMenu new.
customBlocks keysAndValuesDo: [:key :value | menu add: value second asString action: key].
choice := menu startUp.
choice ifNil: [^ self].
customBlocks removeKey: choice
To everyone: (I just noticed this while fixing your code)
I highly recommend using descriptive variable names and not the default ones. Just make sure you have the .changes file so you can keep them!
Offline
yeah normally use descriptive ones but it somehow changed them to t1s and so on. wierd because i have the changes file. i might have right-clicked on something.
anyway thanks for the help it might work
i'll try it now
edit
actually it gives me those default vars (t1 t2 etc) when i copy paste!
Last edited by LS97 (2010-08-13 03:42:01)
Offline
great it works!
now all the block making/deleting is perfect.
i just have a tiny problem
well, a bit bigger.
so, where's the code that actually runs all of those blocks? because i want it so that when i run a block it executes the code directly and not a method with that name.
i think it's somewhere in CommandBlockMorph evaluation, but how exactly can i do that?
Offline
Havent you made a run squeak block. Just use that
Offline
it's not the same thing duh!
Offline
Oh, I dont get what your doing sorry
Offline
never mind
Offline
bump. look @ post 12 plz
Offline
Okay, I think what I did is basically a whole bunch of compiling: (ugh, this took me FOREVER to make for Panther 1.0)
customBlockCode
| oCode temps assignments code i isComment isQuote |
oCode _ customBlockOrigin blockContents: customBlockName.
code _ ''.
isComment _ false.
isQuote _ false.
oCode do: [:let |
let = $' ifTrue: [
isComment ifFalse: [ isQuote _ isQuote not.
code _ code, let asString]]
ifFalse: [
isQuote ifTrue: [
code _ code, let asString]
ifFalse: [
let = $" ifTrue: [
isComment _ isComment not]
ifFalse: [
isComment ifFalse: [code _ code, let asString]]]]].
temps _ ''.
i _ 1.
[i <= self argumentCount] whileTrue: [
temps _ temps, (' t', i asString).
i _ i + 1.].
code lines size = 0 ifTrue: [^ ''].
[code lines first isEmpty] whileTrue: [code _ code copyFrom: 2 to: (code size)].
((code lines first asString findString: '|') > 0) ifTrue: [
code _ (code copyFrom: 1 to: (code lines first asString findString: '|')), temps, (code copyFrom: ((code lines first asString findString: '|') + 1) to: (code size))] ifFalse: [
code _ '|', temps, ' |
', code].
assignments _ ''.
i _ 1.
[i <= self argumentCount] whileTrue: [
([((self args at: i) size = 0)] ifError: [false]) ifTrue: [assignments _ assignments, (('t', i asString), ' _ '), '''''.
']
ifFalse: [
((self args at: i) isKindOf: String) ifTrue: [
assignments _ assignments, ((('t', i asString), ' _ '''), (self args at: i) asString), '''.
']
ifFalse: [
assignments _ assignments, ((('t', i asString), ' _ '), (self args at: i) asString), '.
']].
i _ i + 1.].
((code lines first asString findString: '|') > 0) ifTrue: [
code _ (code copyFrom: 1 to: (code findString: '|' startingAt: ((code findString: '|') + 1))), '
', assignments, (code copyFrom: ((code findString: '|' startingAt: ((code findString: '|') + 1)) + 1) to: (code size))].
[(code findString: '
') > 0] whileTrue: [code _ code copyReplaceAll: '
' with: '
'].
^ code.
And then ran it:
isCustom ifTrue: [Compiler evaluate: self customBlockCode for: receiver logged: false].
Oh, and I found it very helpful to add the "view code" item to the debug menu of the command block.
Last edited by nXIII (2010-08-14 10:43:13)
Offline
cool! but where do i put it?
Offline
oh right. but where did YOU put it
Offline
oh btw i'm definitely not going to do all that stuff
Offline
i'm not going to remake a compiler.
just need to know where scratch executes its scripts so i ca add a code that redirects to a method stored in an array
Offline
LS97 wrote:
i'm not going to remake a compiler.
just need to know where scratch executes its scripts so i ca add a code that redirects to a method stored in an array
billybob has it on one of his projects.

Offline