标签: computercraft

如何终止Lua脚本?

我如何终止Lua脚本?现在我遇到了exit()问题,我不知道为什么.(这更多是Minecraft ComputerCraft的问题,因为它使用了包含的API.)这是我的代码:

while true do

    if turtle.detect() then

        if turtle.getItemCount(16) == 64 then

            exit() --here is where I get problems

        end

        turtle.dig() --digs block in front of it

    end

end
Run Code Online (Sandbox Code Playgroud)

lua minecraft computercraft

13
推荐指数
1
解决办法
3万
查看次数

如何从表中删除字符串

我一直在尝试找到一种从表中删除字符串的方法,如下所示:

myTable = {'string1', 'string2'}
table.remove(myTable, 'string1')
Run Code Online (Sandbox Code Playgroud)

但我一直没能找到办法去做。有人可以帮忙吗?

string lua lua-table computercraft

6
推荐指数
1
解决办法
2956
查看次数

如何在Lua中将stdout重定向到文件?

我试图将 Lua (5.1) 中的标准输出重定向到文件而不是控制台。

有一个第三方 API(我无法修改)包含一个打印序列化数据集的函数(我不知道哪个函数执行打印,假设某种 print())

这些数据太冗长,无法适应我必须使用的屏幕(无法滚动),因此我希望将函数的输出定向到文件而不是控制台。

我没有能力修补或操作 Lua 版本。

我的想法是使用记录不充分的 io.output() 文件将 stdout 更改为文件,但这似乎根本不起作用。

 io.output("foo")   -- creates file "foo", should set stdout to "foo"?
 print("testing. 1, 2, 3") -- should print into "foo", goes to console instead
Run Code Online (Sandbox Code Playgroud)

有谁知道有什么方法可以强制函数输出到文件中,或者强制所有标准输出到文件而不是控制台中?TIA。

lua stdout computercraft

5
推荐指数
1
解决办法
8568
查看次数

如何运行像'挖掘5'这样的计算机程序

有人可以告诉我命令,所以我可以制作如下程序:

'计划19'或
'建造房屋5 3 10'

而不是依赖input = read()

我一直在寻找它,并且还没有想出来或发现它,所以如果有人可以告诉我,如果没有人可以,那就好了,谢谢你的时间.

因为该网站不会让我发布这个问题,除非我得到了一些帮助解决问题,生病的代码将使用它当前使用读取方法.

input = read()   
if input == "right" then  
  for k, v in ipairs(peripheral.getMethods(input)) do  
    print(k,", ",v)  
  end
Run Code Online (Sandbox Code Playgroud)

我认为如果我可以'扫描正确'而不是'扫描''正确'代码会更酷

lua minecraft computercraft

5
推荐指数
1
解决办法
6585
查看次数

在同一(匿名)表中使用表键

我想在同一个表中的匿名表中使用密钥,如下所示:

loadstring( [[return {
  a = "One",
  b = a.." two"
}]] )
Run Code Online (Sandbox Code Playgroud)

从我的角度来看,这应该返回下表:

{ a = "One", b = "One two" }
Run Code Online (Sandbox Code Playgroud)

然而,它只是返回nil这可以做到吗?如何做到?

lua computercraft

2
推荐指数
1
解决办法
755
查看次数

在lua中使用函数作为参数

只是乱搞计算机技术,尝试使用函数作为参数,但不能让它工作

bla = function() print("bla") end
execfunc = function(func) func() end
execfunc(bla())
Run Code Online (Sandbox Code Playgroud)

我想做一些如上所示的事情,但是使用工作代码而不是废话

lua computercraft

1
推荐指数
1
解决办法
1707
查看次数

Lua"if then"语句出错(预期'结束'(在第28行关闭'if'))

我收到了一个错误

bios:14: [string "Lighting"]:58: 'end' expected (to close 'if' at line 28) 
Run Code Online (Sandbox Code Playgroud)

老实说我不知道​​自己刚开始做Lua和编码时我在做什么.我认为它与没有end某个地方有关.

term.clear()
term.setCursorPos(17, 4)
print("Welcome")
sleep(2)
term.setCursorPos(8, 5)
print("What lights would you like to control?")
input = read()
if input == "Hall" then
  term.clear()
  term.setCursorPos(17,4)
  print("On or Off?")
  input = read()
  if input == "on" then
    redstone.setOutput("back", true)
    print("Hall Lighting Turned On")
    sleep(5)
    shell.run("Lighting")
  else
    redstone.setOutput("back", false)
    print("Hall Lighing Turned Off")
    sleep(5)
    shell.run("Lighting")
  if input == "Bedroom" then
  term.clear()
  term.setCursorPos(17,4)
  print("On or Off")
  input = read() …
Run Code Online (Sandbox Code Playgroud)

lua computercraft

1
推荐指数
1
解决办法
595
查看次数

标签 统计

computercraft ×7

lua ×7

minecraft ×2

lua-table ×1

stdout ×1

string ×1