如何在Lua中使用命令行参数来调用表格

我正在尝试制作一个能够根据特定条件运行程序的程序。基本上,我正在使用Minecraft和乌龟的ComputerCraft来检索物品,然后回到起点。我在代码中将所有坐标单独存储在表格中,如您所见。但每次运行它时,它都不起作用,因为goto程序的用法不正确。问题在于坐标表格没有正确调用,我不知道该如何做。goto命令的用法如下:goto <x> <y> <z> [f]。X、Y和Z是坐标,f是方向。这是代码的pastebin链接:http://pastebin.com/i73w0S1m

点赞
用户1847592
用户1847592
local tArgs = {...}
if not tArgs[1] then
  print("用法: request <物品名称> <数量>")
  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))
2013-04-20 16:05:27
用户88888888
用户88888888
好的,那么按照这样的方式操作就可以了 =)嗯,关于处理器代码我不是很清楚,但我刚刚修复了使用代码 =)

local tArgs = {...} function usage() print("用法:request < 物品名字 > < 数量 >") 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 哈哈,不好意思,我意外修改了 Egor Skriptunoff 的代码 XD

2016-12-12 22:47:30