I’m trying to implement a loading and saving routine so that a game quit while in progress can be resumed when the app is relaunched.
The problem I’ve run into is that the basic demo routine doesn’t handle data in tables well.
[lua]if (dataTable) then
file = io.open( filePath, “w” )
for k,v in pairs( dataTable ) do
file:write( k … “=” … v … “,” )
end
io.close( file )[/lua]
Not knowing a better way to parse data in single variables and tables, I’ve broken them out individually:
[lua]dataTable.gameEnded = gameEnded
dataTable.x1 = enemyList[1].x[/lua]
This works fine when the key/value pair has the same key name as the variable I want to restore upon reload. gameEnded = the value associated with gameEnded. The problem comes in when I’m breaking out the array into pieces. In order to reload enemyList[1].x I need to identity x1 in the table as the key and associate it with enemyList[1].x and repeat that across some 40 array variables.
I’m hoping someone can either suggest a better key/value reading/loading routine or suggest a way to load the data without checking each key for a match against the actual variable name like so:
[lua]if k = “x1” then enemyList[1].x = tonumber(v) end[/lua]
Thanks. [import]uid: 1560 topic_id: 2426 reply_id: 302426[/import]