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

#26 2010-08-15 19:38:35

rubiks_cube_guy238
Scratcher
Registered: 2009-07-02
Posts: 100+

Re: Array problems - nXIII plz repy (again)

nXIII wrote:

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.

um, nxlll, I hat to break this to you, but all that compiling wasn't nescesary. all you really had to do was add the code to set the t1, t2, etc. to the arguments and make sure that it reports the code asUTF8. And this way, the code you use in the block editor isn't at all diferent from real Squeak.


The glass is never half full nor half empty; it is twice as large as it needs to be.

Offline

 

#27 2010-08-15 19:42:01

rubiks_cube_guy238
Scratcher
Registered: 2009-07-02
Posts: 100+

Re: Array problems - nXIII plz repy (again)

LS97 wrote:

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?

Code:

Compiler evaluate: (code) for: receiver logged: false

Here ya go.  smile


The glass is never half full nor half empty; it is twice as large as it needs to be.

Offline

 

#28 2010-08-15 19:44:40

rubiks_cube_guy238
Scratcher
Registered: 2009-07-02
Posts: 100+

Re: Array problems - nXIII plz repy (again)

johnnydean1 wrote:

Havent you made a run squeak block. Just use that

Well, I have. Its here:
http://scratch.mit.edu/static/projects/rubiks_cube_guy238/889306_med.png
and its the block that says 'Code'. Its colapsable too.  tongue   smile


The glass is never half full nor half empty; it is twice as large as it needs to be.

Offline

 

#29 2010-08-15 20:20:19

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

Re: Array problems - nXIII plz repy (again)

rubiks_cube_guy238 wrote:

um, nxlll, I hat to break this to you, but all that compiling wasn't nescesary. all you really had to do was add the code to set the t1, t2, etc. to the arguments and make sure that it reports the code asUTF8. And this way, the code you use in the block editor isn't at all diferent from real Squeak.

No... this is the code to set the variables t1, t2, and declare them, and take out unnecessary code to speed up compiling.
And BTW, you apparently missed this:

I wrote:

And then ran it:

isCustom ifTrue: [Compiler evaluate: self customBlockCode for: receiver logged: false].

rubiks_cube_guy238 wrote:

LS97 wrote:

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

Code:

Compiler evaluate: (code) for: receiver logged: false

Here ya go. :)

That is not what he meant...
he meant "what actually evaluates the block" not "what is the Compiler message to run a piece of code"

And please don't triple-post. Thanks :)

Last edited by nXIII (2010-08-15 20:22:39)


nXIII

Offline

 

#30 2010-08-15 21:34:14

rubiks_cube_guy238
Scratcher
Registered: 2009-07-02
Posts: 100+

Re: Array problems - nXIII plz repy (again)

nXIII wrote:

rubiks_cube_guy238 wrote:

um, nxlll, I hat to break this to you, but all that compiling wasn't nescesary. all you really had to do was add the code to set the t1, t2, etc. to the arguments and make sure that it reports the code asUTF8. And this way, the code you use in the block editor isn't at all diferent from real Squeak.

No... this is the code to set the variables t1, t2, and declare them, and take out unnecessary code to speed up compiling.
And BTW, you apparently missed this:

I wrote:

And then ran it:

isCustom ifTrue: [Compiler evaluate: self customBlockCode for: receiver logged: false].

rubiks_cube_guy238 wrote:

LS97 wrote:

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?

Code:

Compiler evaluate: (code) for: receiver logged: false

Here ya go.  smile

That is not what he meant...
he meant "what actually evaluates the block" not "what is the Compiler message to run a piece of code"

And please don't triple-post. Thanks  smile

Sorry about the tripple posting. im to lazy to reduce it to 1 post  tongue .
And anyways, what LS97 wanted to see is probably CommandBlockMorph evaluateWithArgs:
Or you could try to take a look at the ScratchProcess (located in 'Scratch-Execution Engine')


The glass is never half full nor half empty; it is twice as large as it needs to be.

Offline

 

#31 2010-08-16 08:19:40

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

Re: Array problems - nXIII plz repy (again)

Probably evaluateWithArgs:


nXIII

Offline

 

#32 2010-08-17 12:32:59

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

Re: Array problems - nXIII plz repy (again)

ok great htnaks

Offline

 

Board footer