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

#1 2012-10-17 14:15:56

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Help with button actions

I'm using a DialogBoxMorph in Squeak, and need help sending parameters to a button action.

Currently, I have this:

Code:

tempBtn _ self buttonLabel: tempStr
                    action: #doSomething.

How do I make it send a parameter to doSomething when it's clicked?


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#2 2012-10-17 17:48:26

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: Help with button actions

Apparently,

Code:

tempBtn _ self buttonLabel: tempStr
                    action: 'doSomething:' , (t5).

does not work.


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#3 2012-10-17 18:35:56

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

Re: Help with button actions

Just look at DialogBoxMorph >> withButtonsForYes:no:okay:cancel:

buttonRow addMorphBack: (self buttonLabel: 'Yes' localized action: #yes)

Last edited by nXIII (2012-10-17 18:36:31)


nXIII

Offline

 

#4 2012-10-17 18:42:07

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: Help with button actions

nXIII wrote:

Just look at DialogBoxMorph >> withButtonsForYes:no:okay:cancel:

buttonRow addMorphBack: (self buttonLabel: 'Yes' localized action: #yes)

That doesn't really seem to help me find a way to fire a function with a parameter when a button is clicked.  hmm

Let me give more detailed code:

Code:

initialize
    | t1 t2 t3 t4 t5 t6 |
    super initialize.
    self title: 'Latest Projects on Mod Share'.
    t1 _ self buttonLabel: 'Close' action: #delete.
    t2 _ (HTTPSocket httpGet: 'http://modshare.tk/api/getallprojectsinfo/insanity') contents.
    (t2 findString: 'banned')
        > 0
        ifTrue: 
            [DialogBoxMorph inform: 'You are banned from Mod Share and can''t browse it.' title: 'Failed'.
            ^ self].
    t4 _ t2 findTokens: '|'.
    t4 do: 
        [:t7 | 
        t5 _ t7 findTokens: ':'.
        t6 _ self buttonLabel: (t5 at: 2)
                    action: 'self downloadProject:' , (t5 at: 1).
        t6 extent: 200 @ 35.
        mainColumn addMorph: t6].
    buttonRow addMorph: t1

I need the action to fire downloadProject with the parameter shown (element 1 of t5).


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

#5 2012-10-17 19:45:43

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

Re: Help with button actions

jvvg wrote:

That doesn't really seem to help me find a way to fire a function with a parameter when a button is clicked.  hmm

I need the action to fire downloadProject with the parameter shown (element 1 of t5).

That's not how selectors work.

EDIT: Also, name your instance variables with descriptive names. It's bad practice to use decompiled-code-style ones.

Last edited by nXIII (2012-10-17 19:46:42)


nXIII

Offline

 

#6 2012-10-17 20:09:08

jvvg
Scratcher
Registered: 2008-03-26
Posts: 1000+

Re: Help with button actions

nXIII wrote:

jvvg wrote:

That doesn't really seem to help me find a way to fire a function with a parameter when a button is clicked.  hmm

I need the action to fire downloadProject with the parameter shown (element 1 of t5).

That's not how selectors work.

EDIT: Also, name your instance variables with descriptive names. It's bad practice to use decompiled-code-style ones.

Hmm... that's a problem. Do you know any way around that?
They used to have descriptive names, but Squeak changed them on me.


http://tiny.cc/zwgbewhttp://tiny.cc/e1gbewhttp://tiny.cc/zygbewhttp://tiny.cc/izgbew
Goodbye, Scratch 1.4  sad                                                        Hello Scratch 2.0!  smile

Offline

 

Board footer