我有两张图。这些图形具有倒计时功能。当打开卡时,这些图形开始倒计时。当倒计时达到0时,这些图形调用函数"刷新"。这些图形同时调用函数。如何管理?
这里是我的卡图形使用功能的代码:
on refresh
if eCount is not empty then
add 1 to eCount
else
put 0 into eCount
end if
wait 300 milliseconds with messages
if eCount >= 2 then
--dosomething()
put empty into eCount
end if
end refresh
更新——local eCount
on refresh
add 1 to eCount
if eCount >= 2 then
--dosomething()
put 0 into eCount
else if eCount = 1 then
--dosomethingOnce()
put 0 into eCount
end if
end refresh
当两个图形同时调用"刷新"函数时。它调用方法"——dosomethingOnce()"。我该如何修复?
这里是我的图形代码。
on countDown countT
if countT > 0 then
send "countDown countT" to me in 1 secs
else
send "refresh" to card "Main"
end if
end countDown
这是另一个我认为可以解决你的问题的想法(如果我理解正确的话)
local eCount, sPending
on refresh
add 1 to eCount
if not sPending then
put true into sPending
send "doSomething" to me in 100 millisecs
end if
end refresh
on doSomething
if eCount = 1 then
-- execute code for 1 timer
else
-- execute code for more than 1 timer
end if
-- reset flag
put false into sPending
put 0 into eCount
end doSomething
如果两个计时器在彼此100毫秒内完成,则执行多个计时器的代码-否则执行一个计时器的代码。
我的理解是,您希望只有在两个计时器都调用刷新函数时才发生某些事情。
local eCount
on refresh
add 1 to eCount
if eCount >= 2 then
--dosomething()
put 0 into eCount
end if
end refresh
通过将eCount声明为脚本局部变量,在处理程序之前,它将保留其值。当第二次调用refresh时,应该执行'do something'代码。