Page 1 of 1

Count the how any clicks event are generated

Posted: Tue Sep 22, 2015 7:56 am
by kevin007
Hi, All :)

I am beginner in LiveCode, I have a question about how to count number clicks are generated while clicking a button, and store this into a variable. Can you please give me a solution?

Thanks
Kevin

Re: Count the how any clicks event are generated

Posted: Tue Sep 22, 2015 8:13 am
by jmburnod
Hi Kevin,

There is several way to do that :

• You can have a "on mouseup" message in the stack script

Code: Select all

global gMyNumberClic
on mouseup
add 1 to gMyNumberClic
end mouseup
In this case you have to put a "pass mouseup" each time you use mouseup message

Code: Select all

on mouseup
do myStuuf
pass mouseup
end mouseup
• You can also use a front script (this script takes the first place in message hierarchy)

Code: Select all

global gMyNumberClic
on mouseup
add 1 to gMyNumberClic
pass mouseup
end mouseup
Please have a look to :
insert script
pass

Best regards
Jean-Marc

Re: Count the how any clicks event are generated

Posted: Tue Sep 22, 2015 2:15 pm
by dunbarx
Hi.

Do you mean "How many clicks in order to invoke a certain action" or simply, as Jean-Marc indicated, a counter to count clicks?

The first part of the above question would allow you to do one thing if you clicked the button once, a different thing if you double-clicked, yet a different thing if you clicked three times, and so on...

Which is it?

Craig Newman

Re: Count the how any clicks event are generated

Posted: Wed Sep 23, 2015 5:01 am
by kevin007
Hi,

I mean when I click the button variable 'var1' gets the value by 1 if I again click the button the value is incremented by 1 e.t.c, or when I click the button the label of the button is changed to 1 if again click the button the label is changed to 2. is it possible

Thanks
Shalu

Re: Count the how any clicks event are generated

Posted: Wed Sep 23, 2015 2:42 pm
by dunbarx
Hi.

Jean-Marc already answered this, but maybe a couple of examples will help. Make a new button. In its script:

Code: Select all

global labelCounter
on mouseUp
   set the label of me to the label of me + 1
   set the currentCount of me to the label of me
   put the label of me into labelCounter
end mouseUp
Every time you click the button, its label is increased by 1. You do not need to initialize the label, since LC assumes that an empty container can be added to in context. There is also a global variable that tracks the label, and that global can be accessed from somewhere else, as long as it is declared in the scripts that need it. I would suggest using the custom property "currentCount" instead, as it need not be declared, and can also be accessed from anywhere.

Craig