Hi,
Hoping someone can help with this. This problem only seems to be happening on my Mac, device builds seem to be working ok at the moment.
Basically, when I use io.write, the program ALWAYS restarts 3 times. The code is supposed to store the day the app was last used, and store this in a json file so that the next time it is opened it can check whether it is a new day or not. At the moment this actually checks for a new minute, to make testing easier. The code is below:
[code]
–main.lua
jsonFile = function( filename, base )
– set default base dir if none specified
if not base then base = system.ResourceDirectory; end
– create a file path for corona i/o
local path = system.pathForFile( filename, base )
– will hold contents of file
local contents
– io.open opens a file at path. returns nil if no file found
local file = io.open( path, “r” )
if file then
– read all contents of file into a string
contents = file:read( “*a” )
io.close( file ) – close the file after using it
end
return contents
end
–retrieve previous date from json file
require “json”
timeTable = json.decode(jsonFile(“date.json”));
local function writeCurrentDayToFile()
–if first time running then ensure previous day has a value
if (contents == nil)then contents = “0”;end
–retrieve current time and store as currentDay
local date = os.date( “*t” )
local currentDay = tostring(date.min);
local previousDay = timeTable.time;
print("\nprev: “…previousDay…” and curr: “…currentDay)
print(“seconds til next day:”…(60 - date.sec)…”\n");
–check to see if it is a new day
if(currentDay ~= previousDay)then
print(“new day”);
isNewDay =true;
else
print(“same day”);
end
–write current day to json for next app opening
local path = system.pathForFile( “date.json” )
local fh= io.open(path, “w”);
if fh then
local dateTable = {time = tostring(date.min)};
fh:write(json.encode(dateTable));
end
–]]
io.close(fh);
end
writeCurrentDayToFile();
–…main called after al this[/code]
Does anyone have any idea why this happens, every single time. It’s not even a function that’s called every frame, nor does it carry on forever. It’s always 3 times?! The app then runs as normal, however the problem this causes is that when it is a ‘new day’ I only see the new day screen for a split second - unless I’m fortunate enough for the ‘new day’ to fall on the 3rd refresh.
Any help would be greatly appreciated. [import]uid: 84115 topic_id: 16511 reply_id: 316511[/import]
[import]uid: 84115 topic_id: 16511 reply_id: 61709[/import]
[import]uid: 12482 topic_id: 16511 reply_id: 66649[/import]