Timer 如何实现一个计时器和一个活代码?
我在做双人游戏。用户可以点击配对,效果非常好。但是,我想添加一个计时器。我不知道该怎么做Timer 如何实现一个计时器和一个活代码?,timer,livecode,Timer,Livecode,我在做双人游戏。用户可以点击配对,效果非常好。但是,我想添加一个计时器。我不知道该怎么做 我已经有一个“开始”按钮,用来启动和重置游戏。我添加了一个字段“counter”,用于显示时间。我只是不知道如何在不妨碍游戏的情况下让计时器工作。你问的问题并不完全清楚。你写下你想要一个计时器,但你没有说你想用它做什么。也不是说你想让这个计时器实际显示时间,或者你只是想在一段特定的时间后发生一些事情 以下是显示时间的简单方法: on showTime put the long time into fld
我已经有一个“开始”按钮,用来启动和重置游戏。我添加了一个字段“counter”,用于显示时间。我只是不知道如何在不妨碍游戏的情况下让计时器工作。你问的问题并不完全清楚。你写下你想要一个计时器,但你没有说你想用它做什么。也不是说你想让这个计时器实际显示时间,或者你只是想在一段特定的时间后发生一些事情 以下是显示时间的简单方法:
on showTime
put the long time into fld "Time"
send "showTime" to me in 100 milliseconds
end showTime
通过每100毫秒参考一次时间,显示的时间永远不会超过1/10秒
这里有一种显示计时器的有效方法,它只显示小时和分钟。它及时发送showTime消息,并使用最小的处理能力:
on mouseUp
if showTime is in the pendingMessages then
put the pendingMessages into myMsgs
filter myMsgs with "*showTime*"
repeat for each line myMsg in myMsgs
cancel item 1 of myMsg
end repeat
else
showTime
end if
end mouseUp
on showTime
set the itemDel to colon
put the system time into myTime
put myTime into fld 1
put item 2 of myTime into myMinutes
if myMinutes is 59 then
add 1 to item 1 of myTime
if item 1 of myTime >= 24 then
put 0 into item 1 of myTime
end if
put "00" into item 2 of myTime
else
add 1 to item 2 of myTime
end if
convert myTime to seconds
put myTime - the seconds into myTime
send "showTime" to me in myTime seconds
end showTime
您可以通过单击包含mouseUp处理程序的按钮来启动计时器,也可以通过再次单击相同的按钮来停止计时器
如果这不是您需要的,请解释更多。您的要求并不完全清楚。你写下你想要一个计时器,但你没有说你想用它做什么。也不是说你想让这个计时器实际显示时间,或者你只是想在一段特定的时间后发生一些事情 以下是显示时间的简单方法:
on showTime
put the long time into fld "Time"
send "showTime" to me in 100 milliseconds
end showTime
通过每100毫秒参考一次时间,显示的时间永远不会超过1/10秒
这里有一种显示计时器的有效方法,它只显示小时和分钟。它及时发送showTime消息,并使用最小的处理能力:
on mouseUp
if showTime is in the pendingMessages then
put the pendingMessages into myMsgs
filter myMsgs with "*showTime*"
repeat for each line myMsg in myMsgs
cancel item 1 of myMsg
end repeat
else
showTime
end if
end mouseUp
on showTime
set the itemDel to colon
put the system time into myTime
put myTime into fld 1
put item 2 of myTime into myMinutes
if myMinutes is 59 then
add 1 to item 1 of myTime
if item 1 of myTime >= 24 then
put 0 into item 1 of myTime
end if
put "00" into item 2 of myTime
else
add 1 to item 2 of myTime
end if
convert myTime to seconds
put myTime - the seconds into myTime
send "showTime" to me in myTime seconds
end showTime
您可以通过单击包含mouseUp处理程序的按钮来启动计时器,也可以通过再次单击相同的按钮来停止计时器
如果这不是您需要的,请解释更多。考虑到这是一个游戏,我希望您希望显示秒数,并在一段时间后结束游戏 LiveCode对此有很好的语法。“发送”命令允许您在指定的时间内发送消息。例如:
send "handlerName" to target in 1 second
所以应用这个原理,我们可以在几行脚本中创建计时器
local sSeconds
on countSeconds
add 1 to sSeconds
send "timerIncrease" to me in 1 second
end countSeconds
这个例子将永远计算,所以可能没有那么有用
你描述了一个简单的游戏,所以我想你想从60秒倒计时到0秒。当你点击0时,告诉用户他们的时间到了。T在你的按钮中,你可以尝试以下脚本
local sGameSeconds
local sTimerRunning
on mouseUp
if the label of me is "start" then
set the label of me to "reset"
put true into sTimerRunning
put 60 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 timerRun
if sTimerRunning is true then
subtract 1 from sGameSeconds
if sGameSeconds < 1 then
put 0 into field "counter"
put false into sTimerRunning
set the label of button "start" to "start"
timerFinished
else
put sGameSeconds into field "counter"
send "timerRun" to me in 1 second
end if
end if
end timerRun
on timerFinished
answer "Time Up!"
end timerFinished
local sgames秒
局部激励运行
关于鼠标
如果我的标签是“开始”,那么
将我的标签设置为“重置”
在刺激运行中实现
把60秒放在60秒之内
在1秒内发送“timerRun”给我
其他的
将我的标签设置为“开始”
将false放入刺激运行
将60放入字段“计数器”
如果结束
结束鼠标
论时间
如果sTimerRunning为真,则
秒减去1
如果SGA秒数小于1,则
将0放入字段“计数器”
将false放入刺激运行
将按钮“开始”的标签设置为“开始”
计时器完成
其他的
在“计数器”字段中输入秒数
在1秒内发送“timerRun”给我
如果结束
如果结束
结束计时器
按时完成
回答“时间到了!”
结束时间结束
考虑到这是一个游戏,我希望您希望显示秒数,并在一段时间后结束游戏
LiveCode对此有很好的语法。“发送”命令允许您在指定的时间内发送消息。例如:
send "handlerName" to target in 1 second
所以应用这个原理,我们可以在几行脚本中创建计时器
local sSeconds
on countSeconds
add 1 to sSeconds
send "timerIncrease" to me in 1 second
end countSeconds
这个例子将永远计算,所以可能没有那么有用
你描述了一个简单的游戏,所以我想你想从60秒倒计时到0秒。当你点击0时,告诉用户他们的时间到了。T在你的按钮中,你可以尝试以下脚本
local sGameSeconds
local sTimerRunning
on mouseUp
if the label of me is "start" then
set the label of me to "reset"
put true into sTimerRunning
put 60 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 timerRun
if sTimerRunning is true then
subtract 1 from sGameSeconds
if sGameSeconds < 1 then
put 0 into field "counter"
put false into sTimerRunning
set the label of button "start" to "start"
timerFinished
else
put sGameSeconds into field "counter"
send "timerRun" to me in 1 second
end if
end if
end timerRun
on timerFinished
answer "Time Up!"
end timerFinished
local sgames秒
局部激励运行
关于鼠标
如果我的标签是“开始”,那么
将我的标签设置为“重置”
在刺激运行中实现
把60秒放在60秒之内
在1秒内发送“timerRun”给我
其他的
将我的标签设置为“开始”
将false放入刺激运行
将60放入字段“计数器”
如果结束
结束鼠标
论时间
如果sTimerRunning为真,则
秒减去1
如果SGA秒数小于1,则
将0放入字段“计数器”
将false放入刺激运行
将按钮“开始”的标签设置为“开始”
计时器完成
其他的
在“计数器”字段中输入秒数
在1秒内发送“timerRun”给我
如果结束
如果结束
结束计时器
按时完成
回答“时间到了!”
结束时间结束
你至少应该显示一些代码,即使它不起作用。你至少应该显示一些代码,即使它不起作用。我想我必须承认马克。我写过类似的游戏作为示例堆栈,通常在几秒钟内倒计时。如果这不是他们想要的,他们可以发表评论,我会尽力进一步帮助他们。最终,LiveCode问题的答案将进入公共领域,这很好,所以也感谢您回答这个问题。嗨,马克,很抱歉您有这种感觉。我对个人信用评级没什么兴趣。堆栈溢出已经成为一种非常重要的开发人员资源,因此我们所有(LiveCode开发人员)都对增加使用LiveCode标记的问题和答案的数量感兴趣。当新用户在线搜索时,为他们提供答案尤为重要。没有秘密,我们的意图是非常透明的。发布所问问题,直接在SO上回答,并将链接发送给写支持的人。如果用户需要澄清,我们希望他们能发回t