Count the how any clicks event are generated

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
kevin007
Posts: 40
Joined: Mon Sep 21, 2015 7:46 am

Count the how any clicks event are generated

Post by kevin007 » Tue Sep 22, 2015 7:56 am

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
--
Thanks
Kevin

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Count the how any clicks event are generated

Post by jmburnod » Tue Sep 22, 2015 8:13 am

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
https://alternatic.ch

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Count the how any clicks event are generated

Post by dunbarx » Tue Sep 22, 2015 2:15 pm

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

kevin007
Posts: 40
Joined: Mon Sep 21, 2015 7:46 am

Re: Count the how any clicks event are generated

Post by kevin007 » Wed Sep 23, 2015 5:01 am

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
--
Thanks
Kevin

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: Count the how any clicks event are generated

Post by dunbarx » Wed Sep 23, 2015 2:42 pm

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

Post Reply