hi bjb,
it is not the mysterious me, it is the difference between a local and a global variable.
I'm sorry, in my last post I just looked at your button that does the counting.
But here you have a good example of the difference in scope of the variables. For your stack you could go 2 ways.
If you want to have a field that indicates the number of mouseUp then you could go this way
Code: Select all
on mouseUp theButton
if field "fldcount" = "" or field "fldcount" is not a number then put 0 into myCounter
else put field "fldcount" into myCounter
if theButton is 1 then
add 1 to myCounter
else if theButton is 3 then
subtract 1 from myCounter
end if
put myCounter into field fldCount
set the label of me to myCounter
end mouseUp
This way you have the persistence of the value in the field. This works with the stack you have posted on revonline.
More generally speaking of persistence of a variable: the use of local myCounter did just that, myCounter persisted between calls, but only the script of the button had access to myCounter.
If you declare myCounter as a global variable then you could have declared it also in the script of the clear button and you would have access to myCounter. Then you could have 'cleared' myCounter from whatever script where you had declared myCounter as a global variable.
Does all this matter at all if you could stuff the value of a varible into a field for persistence? You would not want to have more fields than necessary, because accessing a field is slower than a local variable. But if you want to have an easy way to preserve a variable betwen restarts then you might want to put it into a field. (Another way would be to store it in a private property, but you have to get used to using private properties which at first sight are not as intuitive as a field)
The mysterious me is actually not that mysterious at all. It refers to the object where you use it, you just have to specify what you want. You could say "set the label of me to "JustALabel"" and a button would duely set its label to JustALabel, just telling a button from its own script "subtract one from me" doesnt help the button because me is a reserved keyword and not a variable that you can script into. So with me you address properties of an object.
Sorry if this is a little long but I think you have to sort this out somehow. It reminds me of my learning of foreign languages (computer or others) At first there is a long time of frustration: I know what I want to say but nobody wants to understand me... After a while the language and I get along, et voila...
Keep the problems coming,
cheers
Bernd