首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NLua:无法将“Command[]”类型的对象转换为“System.Object[]”类型

NLua:无法将“Command[]”类型的对象转换为“System.Object[]”类型
EN

Stack Overflow用户
提问于 2018-01-28 20:23:06
回答 1查看 179关注 0票数 0

我有一个游戏引擎,它使用NLua编写脚本。但是,我似乎无法访问Command数组中的元素:

代码语言:javascript
复制
-- 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
end

MainBuffer是一个BufferedCommand类型的对象,它包含Command结构数组,称为“持有”、“发布”和“按压”。Command结构包含两个枚举属性,按钮,类型为Button (a标志枚举),Directions类型为Direction (另一个标志枚举)。

当我尝试运行这个脚本时,我会得到标题中的错误。为什么它要向System.Object[]转换呢?有什么办法绕过这件事吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-28 20:38:09

由于LuaInterface文档的提示,我解决了这个问题,我认为这是NLua的基础。

显然,您不能在NLua中以这种方式访问数组。这很烦人,但是您必须像这样使用Array.GetValue()方法:

代码语言:javascript
复制
-- 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

再说一遍,我不喜欢这个,但是如果有人有办法把它转换成适当的数组索引,我很想知道!但就目前而言,这做了我想做的事。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48490912

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档