Just playin' around

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Just playin' around

Michael Rice
A TextMorph (string '15') and two SimpleButtons, one with a '+' and the other with a '-'.

Target for both buttons is the TextMorph. The following, executed (with DoIt) in the bottom subwindow of the '+' button inspector increments the TextMorph by 1.

(self target) contents: ((((self target) getNumericValue) + 1) printStringBase: 10).

However, a Viewer for the '+' button seems to have no target variable. And a script for the button rejects "button up?" and "button down?" tests with error messages.

Seems I'm trying to hook up some incompatible things. How would one hook up these three morphs, simply?

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Just playin' around

Nicola Mingotti

I am a beginner, like you, and I learnt how to bind buttons to actions from the Workspace a few days ago :)

So, here is a minimal working snippet. Run one line at a time for best fun. First line is only to clean already existing widgets. I did not put the Layout stuff to keep things as easy/nice as possible.

--------------------
"Run this line to clean up and restart testing. Not useful on first run "
s delete. bp delete. bm delete.

s := StringMorph new.
s openInWorld .
s contents: '0'.
s position: 100@100.

bp := SimpleButtonMorph new.
bp openInWorld .
bp label: 'Plus-1'.
bp position: 150@100.

bm := SimpleButtonMorph new.
bm openInWorld .
bm label: 'Minus-1'.
bm position: 250@100.

"------ Add actions to buttons ------------ "
bp target: [ s contents: (s contents asInteger + 1) asString ].
bp actionSelector: #value.

bm target: [ s contents: (s contents asInteger - 1) asString ].
bm actionSelector: #value.

--------------------

bye
Nicola





On 8/13/19 12:40 PM, Michael Rice wrote:
A TextMorph (string '15') and two SimpleButtons, one with a '+' and the other with a '-'.

Target for both buttons is the TextMorph. The following, executed (with DoIt) in the bottom subwindow of the '+' button inspector increments the TextMorph by 1.

(self target) contents: ((((self target) getNumericValue) + 1) printStringBase: 10).

However, a Viewer for the '+' button seems to have no target variable. And a script for the button rejects "button up?" and "button down?" tests with error messages.

Seems I'm trying to hook up some incompatible things. How would one hook up these three morphs, simply?

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners