2013-04-20 62 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