Mike: Save/Load should work now; TODO updated
This commit is contained in:
@@ -2,15 +2,15 @@ GameState = {}
|
||||
|
||||
-- Supply the table then the name of the table in string format
|
||||
function GameState.save(tbl, table_name)
|
||||
file = io.open("save_game/savefile.lua", "w")
|
||||
io.output(file)
|
||||
print_table(tbl, table_name)
|
||||
io.close(file)
|
||||
saved_table = print_table(tbl, table_name)
|
||||
return saved_table
|
||||
|
||||
end
|
||||
|
||||
|
||||
function GameState.load()
|
||||
dofile("save_game/savefile.lua")
|
||||
function GameState.load(SAVE_FILE)
|
||||
-- Pretty sure doing this slash will break it on winblows
|
||||
dofile(love.filesystem.getSaveDirectory().. "/" .. SAVE_FILE)
|
||||
end
|
||||
|
||||
function printf (s, ...)
|
||||
@@ -20,24 +20,31 @@ end
|
||||
function print_table(tbl, table_name, only_once)
|
||||
if only_once == nil then
|
||||
printf("%s = { ", table_name)
|
||||
saved_table = table_name .. " = { "
|
||||
end
|
||||
for key,value in pairs(tbl) do
|
||||
if type(value) == "table" then
|
||||
printf("%s = { ",key)
|
||||
saved_table = saved_table .. key .. " = { "
|
||||
print_table(value, table_name, true)
|
||||
printf("}, ")
|
||||
saved_table = saved_table .. "}, "
|
||||
end
|
||||
if type (value) ~= "table" then
|
||||
if type(value) == "string" then
|
||||
printf("%s = \"%s\", ", key, value)
|
||||
saved_table = saved_table .. key .. " = \"" .. value .. "\", "
|
||||
else
|
||||
printf("%s = %d, ", key, value)
|
||||
saved_table = saved_table .. key .. " = " .. value .. ", "
|
||||
end
|
||||
end
|
||||
end
|
||||
if only_once == nil then
|
||||
printf("}")
|
||||
saved_table = saved_table .. "}"
|
||||
end
|
||||
return saved_table
|
||||
end
|
||||
|
||||
--Counts contents of tables of tables as well
|
||||
|
||||
Reference in New Issue
Block a user