2013-04-20 39 views
0

我正在试图制作一个程序,该程序可以在某些条件下运行程序。基本上,我使用Computercraft与Minecraft和一只乌龟来检索项目,然后返回到它开始的位置。我可以在代码中看到每个表格中的所有坐标。但是每次运行它时都不起作用,因为goto程序的用法不正确。会发生什么情况是坐标表没有正确调用,我不知道该怎么做。 goto命令的用法如下:goto <x> <y> <z> [f]。 X,Y和Z是坐标,f是方向。这里有一个引擎收录的代码:http://pastebin.com/i73w0S1m如何使用lua中的命令行参数调用表

回答

1
local tArgs = {...} 
if not tArgs[1] then 
    print("Usage: request <item name> <amount>") 
    return 
end 
local currentPOS = {gps.locate()} 
local im = peripheral.wrap("left") 
local all_items = { 
    diamond = { -300, 64, -190, 1 }, 
    cobble = { -300, 65, -190, 1 }, 
    ... 
    brass = { -299, 66, -189, 0 }, 
    copper = { -299, 67, -189, 0 }, 
} 
shell.run("goto", unpack(all_items[tArgs[1]])) 
im.suck(0, tArgs[2]) 
shell.run("goto", unpack(currentPOS)) 
0

确定,所以不喜欢这样,这将工作对我来说=)好吧,我duno约之处理的代码,但我只是固定的用法码=)

local tArgs = {...} 
    function usage() 
    print("Usage: request <item name> <amount>") 
     return 
    end 
    if #tArgs < 1 then 
     usage() 
    else 
    if #tArgs > 2 then 
    usage() 
    else 
    local currentPOS = {gps.locate()} 
    local im = peripheral.wrap("left") 
    local all_items = { 
     diamond = { -300, 64, -190, 1 }, 
     cobble = { -300, 65, -190, 1 }, 
     ... 
     brass = { -299, 66, -189, 0 }, 
     copper = { -299, 67, -189, 0 }, 
    } 
    shell.run("goto", unpack(all_items[tArgs[1]])) 
    im.suck(0, tArgs[2]) 
    shell.run("goto", unpack(currentPOS)) 
    end 
    end 

你有希望它有效= D XD斯里我不小心编辑了Egor Skriptunoff代码XD