【问题标题】:Lua script wont accept argsLua 脚本不接受参数
【发布时间】:2014-08-07 15:08:08
【问题描述】:

我试图让全息投影仪工作,但遇到了这些错误:

bad arguments #3 (number expected, got no value)

我的脚本是:

local component = require("component")
local hologram = component.hologram

function setVoxel(x, y, z, value)
  print(x)
  print(y)
  print(z)
  print(value)
  local current = hologram.get(x, z)
  local positiveMask = bit32.lshift(1, y - 1)
  if value then
    hologram.set(x, z, bit32.bor(current, positiveMask))
  else
    local negativeMask = bit32.bnot(positiveMask)
    hologram.set(x, z, bit32.band(current, negativeMask))
  end
end

local args = {...}
print(args[1])
print(args[2])
print(args[3])
print(args[4])
setVoxel(tonumber(args[1]), tonumber(args[2]), tonumber(args[3]), args[4])

我用过:

holo-set 8 16 20 true

返回的打印命令:

8
16
20
true

但它不起作用。 我检查了拼写。 全息图也已正确初始化。

【问题讨论】:

  • “opencomputers”是什么意思?没有描述,这是该标签的唯一问题。 (我认为“我的世界”在某种程度上是相关的,但我在问题中看不到任何关于它的内容。)
  • @KeithThompson 我想(阅读:我的最佳猜测)opencomputers 是他用来在 Minecraft 中获取计算机的模组。

标签: lua minecraft lua-5.2 opencomputers


【解决方案1】:

那个错误意味着某个函数(错误的其余部分是什么?)期望得到三个参数,结果却得到了两个。

鉴于该代码 sn-p 我能看到的唯一可能适用的函数是 hologram.get。

快速浏览一下文档(感谢 Google),实际上似乎需要 three arguments。

get(x:number, y:number, z:number):number
Returns the value at the specified position.

【讨论】:

    猜你喜欢
    • 2017-05-23
    • 1970-01-01
    • 2012-09-17
    • 1970-01-01
    • 2016-08-03
    • 2021-06-07
    • 1970-01-01
    • 2013-06-21
    • 2015-09-15
    相关资源
    最近更新 更多