【问题标题】:Lua: shell.run('asdf','arg1','arg2') Arguments? Tagging?Lua: shell.run('asdf','arg1','arg2') 参数?标记?
【发布时间】:2014-08-25 09:59:02
【问题描述】:

参数有什么作用?如何在某处为 shell.run('asdf') 编写标签并将其链接到 shell.run('asdf') 行? 代码:

  turtle.dig()
  turtle.forward()
 -what api works with shell.run() here?-  <---------- Where I want tag.
  turtle.digUp()
  turtle.dig()
  turtle.turnLeft()
  turtle.dig()
  turtle.turnRight()
  turtle.up()
if turtle.detect() then
  shell.run('asdf')        <---------- What do I put to link it to tag.
else
  turtle.forward()
  turtle.turnLeft()
end
  while not turtle.detectDown() do
    turtle.dig()
    turtle.down()
  end
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.turnLeft()

【问题讨论】:

  • 这不是普通的 Lua。请给出上下文。
  • 看起来像计算机。 computercraft.info
  • 它的计算机技术是事实。

标签: lua computercraft


【解决方案1】:

shell.run 运行一个命令,就好像你在命令行中输入了它一样。我认为您将它与 goto 混淆了,这有很大不同。

shell.run 的参数作为参数传递给命令行。

例如。 shell.run("ls") 将运行 ls 命令,shell.run("rm", "foo.txt") 将运行 rm foo.txt

【讨论】:

    【解决方案2】:

    这里使它成为一个函数:

      turtle.dig()
      turtle.forward()
      function tag() -- function
    
        turtle.digUp()
       turtle.dig()
       turtle.turnLeft()
       turtle.dig()
      turtle.turnRight()
       turtle.up()
    if turtle.detect() then
     tag() -- running the function
     else
      turtle.forward()
      turtle.turnLeft()
     end
      while not turtle.detectDown() do
           turtle.dig()
        turtle.down()
      end
     turtle.turnLeft()
     turtle.forward()
     turtle.forward()
     turtle.turnLeft()
     turtle.turnLeft()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-14
      • 2011-08-28
      • 2020-12-27
      • 1970-01-01
      • 1970-01-01
      • 2011-09-12
      • 2013-05-01
      相关资源
      最近更新 更多