【问题标题】:How to get a value/variable from a table in corona SDK?如何从电晕 SDK 中的表中获取值/变量?
【发布时间】:2017-06-27 21:01:23
【问题描述】:

如果我想检查一个变量或从我在 corona SDK 中创建的表中获取一个值怎么办?我知道你在 C++ 中使用索引号,但是当我尝试它时它不起作用。

在 main.lua 中:

local table = {}
table.first = "string"
table.second = 25
table.third = "I want to get this one"

loadsave.saveTable(table,"table.json", system.DocumentsDirectory)

在另一个.lua中

local getTable = loadsave.loadTable("table.json", system.DocumentsDirectory)
--here I would like to get the third value from the table and print it

【问题讨论】:

  • getTable.third
  • local table() 不是有效的 Lua。阅读优秀的书籍Programming in Lua 将有助于回答此类极其基本的问题。第一版免费提供online

标签: lua coronasdk


【解决方案1】:

试试这个:

local table = {}
table.third = "I want to get this one"

print( table.third )
===============================
output: "I want to get this one"

Also check this link for more about tables in lua

【讨论】:

    猜你喜欢
    • 2016-07-16
    • 1970-01-01
    • 2017-03-19
    • 1970-01-01
    • 2011-10-05
    • 1970-01-01
    • 1970-01-01
    • 2013-04-12
    • 1970-01-01
    相关资源
    最近更新 更多