如何更新 corona SDK 中的变量?
How to update a variable in corona SDK?
我有一个函数,可以将变量从原来的变量更改为新的变量。我正在使用加载保存 .json 表来获取和加载数据。如何更新 startmoneyTxt 以显示新变量?
我的函数:
local function unlockBall(event)
ballfirst = loadsave.loadTable("firstBall.json", system.DocumentsDirectory)
currentMoney1 = loadsave.loadTable("cashTable.json", system.DocumentsDirectory)
difference = currentMoney1 - ballfirstUnlock
if(ballfirst == 0 and difference >= 0)then
ballfirstID = 1
loadsave.saveTable(ballfirstID, "firstBall.json", system.DocumentsDirectory)
loadsave.saveTable(difference, "cashTable.json", system.DocumentsDirectory)
end
end
我应该更新的代码:
currentMoney = loadsave.loadTable("cashTable.json", system.DocumentsDirectory)
startmoneyTxt= display.newText("$ "..currentMoney.." " , 0,0, "Helvetica", 20)
sceneGroup:insert(startmoneyTxt)
任何时候你想改变文本使用
startmoneyTxt.text = "Your text here"
注意:正如名称 saveTable
和 loadTable
暗示函数缩进到 save/load 表。因此,您可以使用一个文件来 save/load 多个值。
我在我的游戏 The Great Pong.
中使用 loadsave 模块 save/load 设置
我有一个函数,可以将变量从原来的变量更改为新的变量。我正在使用加载保存 .json 表来获取和加载数据。如何更新 startmoneyTxt 以显示新变量?
我的函数:
local function unlockBall(event)
ballfirst = loadsave.loadTable("firstBall.json", system.DocumentsDirectory)
currentMoney1 = loadsave.loadTable("cashTable.json", system.DocumentsDirectory)
difference = currentMoney1 - ballfirstUnlock
if(ballfirst == 0 and difference >= 0)then
ballfirstID = 1
loadsave.saveTable(ballfirstID, "firstBall.json", system.DocumentsDirectory)
loadsave.saveTable(difference, "cashTable.json", system.DocumentsDirectory)
end
end
我应该更新的代码:
currentMoney = loadsave.loadTable("cashTable.json", system.DocumentsDirectory)
startmoneyTxt= display.newText("$ "..currentMoney.." " , 0,0, "Helvetica", 20)
sceneGroup:insert(startmoneyTxt)
任何时候你想改变文本使用
startmoneyTxt.text = "Your text here"
注意:正如名称 saveTable
和 loadTable
暗示函数缩进到 save/load 表。因此,您可以使用一个文件来 save/load 多个值。
我在我的游戏 The Great Pong.
中使用 loadsave 模块 save/load 设置