Android 在corona SDK中保存表

Android 在corona SDK中保存表,android,lua,coronasdk,Android,Lua,Coronasdk,早上好,我正在试着把我的桌子保存在Corona SDK中。当退出和进入游戏时,解锁的关卡仍然必须解锁 我试过好几件事,但还是想不出来。 我怎样才能做到这一点 以下是我的部分代码: G = { Gamescore1=0, Gamescore2=0, Gamescore3=0, Gamescore4=0, Gamescore5=0, Gamescore6=0, Gamescore7=0, Gamescore8=0, Gamescore9=0, } --Gamescore1=0 fu

早上好,我正在试着把我的桌子保存在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,则下一关将解锁

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

例如: Gamescore1=0

addscore1函数被触发,因此现在Gamescore1=1。 如果Gamescore1=1,则下一级解锁。我都准备好了。现在我只需要用新值(1)保存Gamescore1

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


提前谢谢

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

为此,必须以某种方式序列化表,因为不能直接保存表。有无数种方法,所以我在这里不会解释太多。只需在web上搜索Lua表序列化或阅读以下内容:

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

文件内容可能如下所示:

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

选择适合你需要的东西