increment every second

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
thegreatbatsby
Posts: 2
Joined: Mon Nov 17, 2014 12:58 pm

increment every second

Post by thegreatbatsby » Wed Nov 19, 2014 10:05 am

I am designing a game and need to increment a variable every second without preventing the user doing other things. is there any way to do this while avoiding an infinite loop, which prevents the user doing anything else?

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: increment every second

Post by LCNeil » Wed Nov 19, 2014 10:11 am

Hi batsby,

Check out the following stackOverFlow post which should help you with this-

http://stackoverflow.com/questions/2222 ... a-livecode

Kind Regards,

Neil Roger
--
LiveCode Support Team ~ http://www.livecode.com
--

thegreatbatsby
Posts: 2
Joined: Mon Nov 17, 2014 12:58 pm

Re: increment every second

Post by thegreatbatsby » Wed Nov 19, 2014 10:21 am

Thanks, that seems to have stoped the crashing. :D

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: increment every second

Post by [-hh] » Wed Nov 19, 2014 3:52 pm

Neil, I take this back.
I was wrong, thought too much of a timer with a parameter. Sorry for that. This was now more a "youth sin" of me ...

The only thing that remains is, that this is actually counts down to one, because the timer stops at the beginning of zero( .., two, one, "go"). But most people wish to have it like that.

Hermann
Last edited by [-hh] on Wed Nov 19, 2014 6:56 pm, edited 2 times in total.
shiftLock happens

LCNeil
Livecode Staff Member
Livecode Staff Member
Posts: 1223
Joined: Wed Oct 03, 2012 4:07 pm

Re: increment every second

Post by LCNeil » Wed Nov 19, 2014 4:32 pm

Hi hh,

The link provides the information the original poster requested so it should be ok to keep :)

In regards to the counter, would changing the following resolve the issue you are describing-

Code: Select all

on mouseUp
   if the label of me is "start" then
      set the label of me to "reset"
      put true into sTimerRunning
      put 59 into field "counter"
      put 59 into sGameSeconds
      send "timerRun" to me in 1 second
   else
      set the label of me to "start"
      put false into sTimerRunning
      put 60 into field "counter"
   end if
end mouseUp

on timerFinished
   answer "Time Up!"
   put "60" into field "counter"
end timerFinished

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

Re: increment every second

Post by dunbarx » Wed Nov 19, 2014 4:49 pm

There were several threads on this last year, though in this case it sounds like the one-second timer is not, er, time critical.

That thread spoke about using the system clock instead of "sending in time" for greater accuracy. It was called "Accurate timer". Just something to think about.

Craig Newman

Post Reply