我有一个游戏引擎,它使用NLua编写脚本。但是,我似乎无法访问Command数组中的元素:
-- Basic direction detection. This allows forward and backward to cancel each other out if both are active.
function DetectXHoldDirection()
directionDetect = 0
if self.MainBuffer.Hold[0].Directions:HasFlag(Direction.Forward) then
directionDetect = directionDetect + 1
end
if self.MainBuffer.Hold[0].Directions:HasFlag(Direction.Back) then
directionDetect = directionDetect - 1
end
endMainBuffer是一个BufferedCommand类型的对象,它包含Command结构数组,称为“持有”、“发布”和“按压”。Command结构包含两个枚举属性,按钮,类型为Button (a标志枚举),Directions类型为Direction (另一个标志枚举)。
当我尝试运行这个脚本时,我会得到标题中的错误。为什么它要向System.Object[]转换呢?有什么办法绕过这件事吗?
发布于 2018-01-28 20:38:09
由于LuaInterface文档的提示,我解决了这个问题,我认为这是NLua的基础。
显然,您不能在NLua中以这种方式访问数组。这很烦人,但是您必须像这样使用Array.GetValue()方法:
-- Basic direction detection. This allows forward and backward to cancel each other out if both are active.
function DetectXHoldDirection()
directionDetect = 0
if self.MainBuffer.Hold:GetValue(0).Directions:HasFlag(Direction.Forward) then
directionDetect = directionDetect + 1
end
if self.MainBuffer.Hold:GetValue(0).Directions:HasFlag(Direction.Back) then
directionDetect = directionDetect - 1
end
end再说一遍,我不喜欢这个,但是如果有人有办法把它转换成适当的数组索引,我很想知道!但就目前而言,这做了我想做的事。
https://stackoverflow.com/questions/48490912
复制相似问题