【发布时间】:2014-05-24 06:06:19
【问题描述】:
我是lua的新手,昨晚才开始。我为我的游戏编写了一个脚本,但我发现它没有运行。
我的脚本中有三个函数,它们是函数:function shoot()、function pickplayer()和function drinkwater()。
- 连续运行
function shoot()35 秒 - 然后在
function shoot()完成后立即运行 function pickplayer()。 - 将步骤 1 和 2 循环 3 次
- 然后运行
function drinkwater()
我已经单独运行了其中的 3 个函数并且运行良好,但是当我将它们组合在一起时,脚本就无法按我希望的那样运行。因为它无法在 function shoot() 连续运行 35 秒后才跳转到其他功能
如果你们能帮我指出问题出在哪里,那将不胜感激。
我知道问这种愚蠢的问题可能太愚蠢了,但是对于一个不会计算机的人来说,你的帮助会让我有很大的进步
请看下面的脚本
DESCRIPTION=" first script";
function shoot()
while true do
x, y = findImage("/mnt/sdcard/target1.bmp");
x1, y1 = findImageFuzzy("/mnt/sdcard/b7.bmp", 80);
if x1 ~= -1 == x ~= -1 and y1 ~= -1 == y ~= -1 then
touchDown(0, x, y);
touchUp(0)
end
coroutine.yield();
end
end
function pickplayer()
while true do
if findImage("/mnt/sdcard/df.bmp") then
touchDown(0, 355, 783)
touchUp(0)
mSleep(500);
touchDown(0, 188, 203)
touchUp(0)
mSleep(500);
touchDown(0, 196, 196)
touchUp(0)
mSleep(500);
end
mSleep(500);
coroutine.yield();
end
end
function drinkwater()
while true do
if findImage("/mnt/sdcard/noenoughwater.bmp") then
touchDown(0, 228, 479)
touchUp(0)
mSleep(2000);
touchDown(0, 178, 223)
touchUp(0)
mSleep(2000);
touchDown(0, 222, 604)
touchUp(0)
mSleep(2000);
touchDown(0, 180, 218)
touchUp(0)
mSleep(3000);
end
coroutine.yield();
end
end
function main()
co1 = coroutine.create(shoot);
co2 = coroutine.create(pickplayer);
co3 = coroutine.create(drinkwater);
while true do
local timeToRun = 35000
local initialTime = os.time()
local timeElasped=os.difftime(os.time(), initialTime)
while timeElasped < timeToRun do
coroutine.resume(co1)
timeElasped =os.difftime(os.time(), initialTime)
mSleep(2000);
coroutine.resume(co2);
coroutine.resume(co3);
end
end
end
【问题讨论】:
-
按原样运行脚本时会发生什么?
-
感谢您的回复 Etan,未找到错误,只是没有运行
-
我的计时器有什么问题吗?
-
刚刚再次测试,函数co1工作正常,但co 2和co3不行
-
“什么都没有运行”是什么意思?究竟会发生什么?如果您将打印/日志语句放在这些函数中,您会看到它们的输出吗?
标签: lua