Mike: created ability to do 'table = GameState.load(SAVE_FILE)

This commit is contained in:
Logen Kain 2017-07-30 21:03:49 -07:00
parent d75e61bba9
commit b91883b3b8
3 changed files with 9 additions and 5 deletions

View File

@ -13,3 +13,4 @@ Game crashes if I try to save without running it from the dir code: "love ." But
-- I'd also like to make it so I can do "actors = GameState.load(SAVE_FILE)" instead of having the variable (actors) in the save file
-- Should be doable with love.filesystem.read(SAVE_FILE), just need to stop adding in the "VARIABLE =" at the beginning of my save file
-- Also remove the need to put in a string at all this way.
-- Previous idea didn't work, but have created the ability to do "actors = GameState.load(SAVE_FILE)"

View File

@ -1,16 +1,18 @@
GameState = {}
-- Supply the table then the name of the table in string format
function GameState.save(tbl, table_name)
saved_table = print_table(tbl, table_name)
function GameState.save(tbl)
saved_table = print_table(tbl)
return saved_table
end
function GameState.load(SAVE_FILE)
-- Pretty sure doing this slash will break it on winblows
-- placeholder is the name of our placeholder variable
-- so we can do things like "actors = GameState.load"
dofile(love.filesystem.getSaveDirectory().. "/" .. SAVE_FILE)
return placeholder
end
function printf (s, ...)
@ -19,7 +21,8 @@ end
function print_table(tbl, table_name, only_once)
if only_once == nil then
printf("%s = { ", table_name)
table_name = "placeholder"
printf("local %s = { ", table_name)
saved_table = table_name .. " = { "
end
for key,value in pairs(tbl) do

View File

@ -24,7 +24,7 @@ function love.keyreleased(key)
if save_exists then
--player = Tserial.unpack( love.filesystem.read( saveFile ) )
GameState.load(SAVE_FILE)
actors = GameState.load(SAVE_FILE)
end
end
end