For your first question, a canvas gets the click event on mouse-down, and the release event on mouse-up, so you can make the canvas change colour while the button is held down:
on click pos do
me.pattern:colors.red
me.rect[0,0 me.lsize]
end
on release pos do
me.pattern:colors.white
me.rect[0,0 me.lsize]
end
(obviously you can do fancier painting than that if you want)
The release event also gives you the position of the pointer at the time the button was released, relative to the top-left corner of the canvas. If the position is below and to the right of the top-left corner, and above and to the left of the bottom-right corner, then it’s within the canvas, and you can do whatever the canvas-button is supposed to do:
if min (pos>0,0),(pos<me.lsize)
alert["whatever I'm supposed to do"]
end
For your second question, I can’t easily spot an error (though I’m pretty sure you don’t need set); in this situation I’d wrap show[] around different parts of the code to double-check that the values being calculated were the ones I expected. show[] takes a sequence of expressions, logs them to the Listener, and returns the first one, so you can wrap it around expressions without changing how your code runs. So, this code will run exactly the same as the example above:
if min show[(pos>0,0) "<-- to the bottom right"],show[(pos<me.lsize) "<-- to the top left"]
alert["whatever I'm supposed to do"]
end
…but produces this output in the Listener:
(1,1) "<-- to the bottom right"
(0,1) "<-- to the top left"
For your third question, the floor operator drops the fractional part of a number:
floor 1.0,1.4,1.5,1.6,2.0
(1,1,1,1,2)
If you want round-to-nearest rather than always-round-down, you can add 0.5 before hand:
floor 0.5+(1.0,1.4,1.5,1.6,2.0)
(1,1,2,2,2)