【问题标题】:Save table in corona SDK在电晕 SDK 中保存表格
【发布时间】:2016-07-16 02:16:15
【问题描述】:

美好的一天,有一段时间我正在尝试将我的表保存在 Corona SDK 中。退出和进入游戏时,解锁的关卡仍然需要解锁。

我已经尝试了几件事,但我仍然无法弄清楚。 我怎样才能做到这一点?

这是我的代码的一部分:

    G = {
Gamescore1=0,
Gamescore2=0,
Gamescore3=0,
Gamescore4=0,
Gamescore5=0,
Gamescore6=0,
Gamescore7=0,
Gamescore8=0,
Gamescore9=0,
}

    --Gamescore1=0
function addscore1()
G.Gamescore1=G.Gamescore1+1

    -----------------------------------------------------------
end
    ----------------------------------------------------------
function addscore2()
G.Gamescore2=G.Gamescore2+1
end
    ---------------------------

function addscore3()
G.Gamescore3=G.Gamescore3+1
end

function addscore4()
G.Gamescore4=G.Gamescore4+1
end

function addscore5()
G.Gamescore5=G.Gamescore5+1
end

Gamescore6=0
function addscore6()
G.Gamescore6=G.Gamescore6+1
end


function addscore7()
G.Gamescore7=G.Gamescore7+1
end


function addscore8()
G.Gamescore8=G.Gamescore8+1
end

function addscore9()
G.Gamescore9=G.Gamescore9+1
end

注意:Gamescore 变量是为了更上一层楼 如果 Gamescore = 1,则将解锁下一关。

因此,每次激活 addcore 功能时,我都需要保存新的 Gamescore。

示例: 游戏分数1 = 0

addscore1 函数被触发,所以现在 Gamescore1 = 1。 如果 Gamescore1 = 1,则解锁下一个级别。我拥有所有这些设置。现在我只需要用新值 (1) 保存 Gamescore1。

我希望这是足够的信息。如果有人可以帮助我,我将不胜感激。

提前致谢!

【问题讨论】:

    标签: android lua coronasdk


    【解决方案1】:

    当您的程序结束时,表中的值将会丢失。您必须将表保存到文件或数据库中。

    为此,您必须以某种方式序列化您的表格,因为您无法直接保存表格。方法很多,这里就不多解释了。只需在网上搜索 Lua 表序列化或阅读以下内容: http://lua-users.org/wiki/TableSerialization

    您基本上将表格的内容转换为可以写入/读取文件的内容。

    文件内容可能如下所示:

    Gamescore1=1;Gamescore2=0;等等 如果它只有 0 和 1,你可以简单地存储一些二进制表示。

    选择任何适合您的需求。

    【讨论】:

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