-1

好的,我对 lua 和计算机技术几乎完全陌生,但我有很多创造力。我正在尝试编写每秒重新打印一个变量的代码。这是我到目前为止所拥有的:

display = "Loading..."
While true do
 sleep(1)
 term.clear()
 term.setCursorPos(1,1)
 print (display)
end
sleep(3)
display = "hello"

我想用它来渲染 2d 游戏,“显示”变量会经常变化,因此我希望它每秒更新一次。

当我运行代码时,它确实每秒刷新一次,但由于某种原因,我似乎无法让“显示”变量在 3 秒后更改以对其进行测试。

我究竟做错了什么?

4

2 回答 2

1

while true是一个无限循环。脚本永远不会到达sleep(3).

也许您想替换while truefor i=1,3.

于 2015-02-10T23:04:47.690 回答
0

我在 Lua 方面没有经验,但这可能是一个解决方案:关于 SO

在 UI 线程中,运行:

while ((status=lua_resume(L_coroutine, 0)) == LUA_YIELD) {
  semaphore_wait(); /* whatever the appropriate C# call is */
}

“等待响应”应该类似于:

while not results[my_result] do
  coroutine.yield()
end

Lua 中的“传入消息”函数应如下所示:

results[cur_result]=parsed_message
于 2015-02-11T09:52:46.337 回答