【问题标题】:How to call a table using a command line argument in lua如何在 lua 中使用命令行参数调用表
【发布时间】:2013-04-13 21:17:07
【问题描述】:

我正在尝试制作一个可以在某些条件下运行程序的程序。基本上,我将 ComputerCraft 与 Minecraft 和一只乌龟一起使用来检索物品,然后回到它开始的地方。正如您在代码中看到的那样,我将所有坐标单独存储在表格中。但是每次我运行它时,它都不起作用,因为 goto 程序的用法不正确。发生的情况是带有坐标的表没有被正确调用,我不知道该怎么做。 goto 命令的用法如下:goto <x> <y> <z> [f]。 X、Y 和 Z 是坐标,f 是方向。这是代码的粘贴箱:http://pastebin.com/i73w0S1m

【问题讨论】:

    标签: variables lua lua-table computercraft


    【解决方案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))
    

    【讨论】:

      【解决方案2】:

      好的,这样做对我有用 =) 好吧,我不知道处理器代码,但我只是修复了使用代码 =)

       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

      【讨论】:

        猜你喜欢
        • 2014-02-11
        • 2013-01-13
        • 2018-10-08
        • 2021-08-21
        • 2012-11-30
        • 2013-03-04
        • 1970-01-01
        • 1970-01-01
        • 2014-08-03
        相关资源
        最近更新 更多