How do you implement a timer a LiveCode? -
i'm making pairs game. users can click , match pairs working great. however, i'd add timer. i'm not sure how this.
i have button "start" used start , reset game. i've added field "counter" i'll use display time. i'm not sure how make timer work without blocking game play.
considering game expect you're wanting display seconds , end game after period of time.
livecode has great syntax this. 'send' command lets send messages in designated amount of time. example:
send "handlername" target in 1 second
so applying principle allows create timers in couple of lines of script
local sseconds on countseconds add 1 sseconds send "timerincrease" me in 1 second end countseconds
this example count forever might not useful!
you described simple game imagine want count down 60 seconds 0. when hit 0, tell user time up.t in button try following script
local sgameseconds local stimerrunning on mouseup if label of me "start" set label of me "reset" put true stimerrunning put 60 sgameseconds send "timerrun" me in 1 second else set label of me "start" put false stimerrunning put 60 field "counter" end if end mouseup on timerrun if stimerrunning true subtract 1 sgameseconds if sgameseconds < 1 put 0 field "counter" put false stimerrunning set label of button "start" "start" timerfinished else put sgameseconds field "counter" send "timerrun" me in 1 second end if end if end timerrun on timerfinished answer "time up!" end timerfinished
Comments
Post a Comment