【问题标题】:Error with index global in Lua recipe for foldit.orgfoldit.org 的 Lua 配方中的全局索引错误
【发布时间】:2015-08-07 19:48:47
【问题描述】:

我刚刚开始为Foldit 编写脚本。这是我第一次体验Lua,所以我的状态是“有见识的菜鸟”。在我的第一个脚本中,我想打印出contactmap 数据。我已经从http://foldit.wikia.com/wiki/Foldit_Lua_Functions 复制并粘贴了函数。我得到的错误是:

attempt to index global 'structure' (a nil value)

这是我的代码:

segmentCount = structure.GetCount()
print ("Segment count: " .. segmentCount)

for source = 1, segmentCount do
  for target = source + 1, segmentCount do
    inContact = contactmap.IsContact(source, target)
    heat = contactmap.GetHeat(source, target)
    print("Segments "..source..", ".. target..": heat = "..heat)
  end
end

提前感谢您的任何启发。


编辑

问题是我最初加载了 V1 配方,而 foldit 继续将其视为 V1 语法。解决方案是创建一个新的(ScriptV2)配方,并加载完全相同的代码。

【问题讨论】:

    标签: lua global


    【解决方案1】:

    您似乎在按照文档做所有事情。该错误意味着未定义contactmap(具有nil 值)并且代码无法访问其元素。我会检查您正在使用的 Foldit 版本,因为文档说 contactmap 是第 2 版中的新版本。

    【讨论】:

    • 我发现了问题。我最初加载了别人使用 V1 编写的食谱。显然,即使在我加载了自己的脚本(在外部文本编辑器中编写)之后,foldit 仍在考虑将配方视为 V1。当我创建一个新的 (V2) 配方并加载我的脚本时,它运行良好。
    猜你喜欢
    • 2019-08-21
    • 2021-08-04
    • 1970-01-01
    • 2014-01-26
    • 2019-03-01
    • 2016-01-12
    • 2012-08-23
    • 2018-11-11
    • 1970-01-01
    相关资源
    最近更新 更多