Page 1 of 1

increment every second

Posted: Wed Nov 19, 2014 10:05 am
by thegreatbatsby
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?

Re: increment every second

Posted: Wed Nov 19, 2014 10:11 am
by LCNeil
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
--

Re: increment every second

Posted: Wed Nov 19, 2014 10:21 am
by thegreatbatsby
Thanks, that seems to have stoped the crashing. :D

Re: increment every second

Posted: Wed Nov 19, 2014 3:52 pm
by [-hh]
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

Re: increment every second

Posted: Wed Nov 19, 2014 4:32 pm
by LCNeil
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

Re: increment every second

Posted: Wed Nov 19, 2014 4:49 pm
by dunbarx
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