diff --git a/love/mike/TODO b/love/mike/TODO index 75bf2b0..926550c 100644 --- a/love/mike/TODO +++ b/love/mike/TODO @@ -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)" diff --git a/love/mike/lib/GameState.lua b/love/mike/lib/GameState.lua index 3ebc8e1..a7da402 100644 --- a/love/mike/lib/GameState.lua +++ b/love/mike/lib/GameState.lua @@ -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 diff --git a/love/mike/lib/keys.lua b/love/mike/lib/keys.lua index 6c36421..965e8f9 100644 --- a/love/mike/lib/keys.lua +++ b/love/mike/lib/keys.lua @@ -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