Button press every 3 seconds without freezing?

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
DorianReedBased
Posts: 1
Joined: Mon Feb 12, 2024 8:06 pm

Button press every 3 seconds without freezing?

Post by DorianReedBased » Mon Feb 12, 2024 8:19 pm

Im trying to make it so a button can only be pressed every 3 seconds, how would i do this without using the wait command (it freezes the whole stack), thanks in advance :)

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Button press every 3 seconds without freezing?

Post by bn » Mon Feb 12, 2024 8:54 pm

Hi DorianReedBased,

welcome to the forum.

I made a stack that shows one way of preventing a button to fire in less than 3 seconds from the last click.

It uses a 'script local variable' to store the time of the last click.
Such a variable must be declared outside and above of a handler hat uses it. Usually you declare them at the top of the script.
That variable is instantiated with 0. When the button is clicked the milliseconds are stored in the script local variable 'sLastClickTime'
The mouseUp handler checks the interval (3000 milliseconds) and if the time is passed that value then it fires.
Have a look at the script of the button.

Kind regards
Bernd
Attachments
button that fires only after 3 secs after last click.livecode.zip
(1.02 KiB) Downloaded 20 times

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Button press every 3 seconds without freezing?

Post by dunbarx » Mon Feb 12, 2024 9:46 pm

Bernd.

Sure the name of your demo stack is long enough?

Craig

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Button press every 3 seconds without freezing?

Post by bn » Mon Feb 12, 2024 9:49 pm

dunbarx wrote:
Mon Feb 12, 2024 9:46 pm
Bernd.
Sure the name of your demo stack is long enough?
Craig
No, but I ran out of words... :)

Kind regards
Bernd

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Button press every 3 seconds without freezing?

Post by dunbarx » Mon Feb 12, 2024 9:57 pm

I understand.

But couldn't you at least have made it more descriptive?

Craig

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Button press every 3 seconds without freezing?

Post by bn » Mon Feb 12, 2024 10:06 pm

dunbarx wrote:
Mon Feb 12, 2024 9:57 pm
I understand.
But couldn't you at least have made it more descriptive?
Craig
Ok, I am always aiming for baroque titles about half a page long.

How about
This is the story of a press-down device that executes your wishes that you have put into the device in a language they call 'LiveCode' and that will not work unless you waited for at least 3 grains of sand down the hour glass. But then by mysterious magic it will execute the exact same orders it did before.
Kind regards
Bernd

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9670
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Button press every 3 seconds without freezing?

Post by dunbarx » Mon Feb 12, 2024 10:22 pm

Bernd.

Too long.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7239
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Button press every 3 seconds without freezing?

Post by jacque » Tue Feb 13, 2024 6:57 pm

😂
What would I do without you guys. The seriousness and depth of your contributions is uplifting.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”