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

#1 2010-08-12 06:05:04

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Array problems - nXIII plz repy (again)

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

 

#2 2010-08-12 07:19:54

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Array problems - nXIII plz repy (again)

BUMP! pleaaseeeeeeeeeee!!!!!!!!!

Offline

 

#3 2010-08-12 07:22:39

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Array problems - nXIII plz repy (again)

Sorry dont do arrays


You can now reach me on Twitter @johnnydean1_

Offline

 

#4 2010-08-12 07:23:44

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Array problems - nXIII plz repy (again)

Unless its the double ':' as you have 2 meathods.


You can now reach me on Twitter @johnnydean1_

Offline

 

#5 2010-08-12 09:39:20

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Array problems - nXIII plz repy (again)

no that's fine
it's an error to do with the numbers probably!
please someone help! it's making me mad!  mad

Offline

 

#6 2010-08-12 09:45:17

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Array problems - nXIII plz repy (again)

bump

Offline

 

#7 2010-08-12 11:35:11

Daffy22
Scratcher
Registered: 2008-12-15
Posts: 500+

Re: Array problems - nXIII plz repy (again)

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.  smile  Good Job.


http://img201.imageshack.us/img201/1784/logosmalle.png
"Spectacular - 5 Star" -  CNET.com Editor.

Offline

 

#8 2010-08-12 12:18:44

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Array problems - nXIII plz repy (again)

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

 

#9 2010-08-12 12:56:43

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Array problems - nXIII plz repy (again)

it didn't work.

Offline

 

#10 2010-08-12 15:49:41

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Array problems - nXIII plz repy (again)

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 asNumber

the 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  tongue ) 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!  smile


nXIII

Offline

 

#11 2010-08-13 03:41:17

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Array problems - nXIII plz repy (again)

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  smile
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

 

#12 2010-08-13 04:19:12

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Array problems - nXIII plz repy (again)

great it works!
now all the block making/deleting is perfect.
i just have a tiny problem  tongue
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

 

#13 2010-08-13 05:01:08

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Array problems - nXIII plz repy (again)

Havent you made a run squeak block. Just use that


You can now reach me on Twitter @johnnydean1_

Offline

 

#14 2010-08-13 05:22:34

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Array problems - nXIII plz repy (again)

mad  it's not the same thing duh!

Offline

 

#15 2010-08-13 05:27:02

johnnydean1
Scratcher
Registered: 2010-02-12
Posts: 1000+

Re: Array problems - nXIII plz repy (again)

Oh, I dont get what your doing sorry


You can now reach me on Twitter @johnnydean1_

Offline

 

#16 2010-08-13 05:27:55

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Array problems - nXIII plz repy (again)

never mind  smile

Offline

 

#17 2010-08-14 07:03:31

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Array problems - nXIII plz repy (again)

bump. look @ post 12 plz

Offline

 

#18 2010-08-14 10:39:31

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Array problems - nXIII plz repy (again)

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)


nXIII

Offline

 

#19 2010-08-14 10:46:25

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Array problems - nXIII plz repy (again)

cool! but where do i put it?  tongue

Offline

 

#20 2010-08-14 10:47:36

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Array problems - nXIII plz repy (again)

Nowhere! That was just an example!


nXIII

Offline

 

#21 2010-08-14 10:49:17

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Array problems - nXIII plz repy (again)

oh right. but where did YOU put it

Offline

 

#22 2010-08-14 10:50:23

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Array problems - nXIII plz repy (again)

oh btw i'm definitely not going to do all that stuff
http://i35.tinypic.com/1zgwcnm.png

Offline

 

#23 2010-08-14 10:59:53

nXIII
Community Moderator
Registered: 2009-04-21
Posts: 1000+

Re: Array problems - nXIII plz repy (again)

All what stuff?


nXIII

Offline

 

#24 2010-08-14 11:02:14

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Array problems - nXIII plz repy (again)

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

 

#25 2010-08-15 17:57:02

mXsoft11
Scratcher
Registered: 2010-05-10
Posts: 100+

Re: Array problems - nXIII plz repy (again)

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.


http://bannerbreak.com/banners/4/696/129702802765745581.gif

Offline

 

Board footer