0
我希望能夠將corona中的步進器小部件的值傳遞給json文件。到目前爲止,我已經有了我的步進器來顯示並遞增和遞減,並在屏幕上顯示當前值。我已經寫了一個函數來將值保存爲json文件,但我無法調用該函數。我希望能夠在屏幕上有其他值保存爲json的設置。下面的代碼我已經保存設置:將Corona SDK中的步進器的值保存到json文件
local function saveSettings (e)
-- body
print("testtesttest")
if (file) then
local content = file:read("*a")
else
settings = {}
settings.houses = StepperNo
file = io.open(path, "w")
local json_setting = json.encode(settings)
file:write(json_setting)
io.close(file)
end
end
,然後將代碼以顯示步進:
local StepperNo = 1
local displayNoOfHouses = display.newText("Number of houses: "..StepperNo,180,135, native.systemFontBold,16)
local function onStepperPress(e)
if ("increment" == e.phase) then
StepperNo = StepperNo + 1
elseif ("decrement") == e.phase then
StepperNo = StepperNo - 1
end
displayNoOfHouses.text = "Number of houses: "..StepperNo
end
local HouseStepper = widget.newStepper {left = 100, top = 100, minimumValue = 0, maximumValue = 9, onPress = onStepperPress}
我不知道如何按步進後調用savesetting功能。我想我可能會不正確地做到了這一點,或者可以缺少明顯的東西,我是很新的Lua中......