Skip to content

Commit

Permalink
Make autosave exit work properly with serialization of CrimeRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
impaktor committed Oct 28, 2015
1 parent ed12897 commit 6aea8c8
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions data/libs/Player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,20 @@ end
local loaded_data

local onGameStart = function ()

-- Don't reset these in onGameEnd (where they belong), since that
-- sometimes clears out the data before autosave-exit can get to it
-- (call order for event triggers is arbitrary)...
Player.record = {}
Player.record_old = {}

if (loaded_data) then
Game.player:setprop("cash", loaded_data.cash)

-- ...thus we need to manually unserialize them
Player.record = loaded_data.record
Player.record_old = loaded_data.record_old

loaded_data = nil
end
end
Expand All @@ -381,8 +393,6 @@ end

local onGameEnd = function ()
-- clean up for next game:
Player.record = {}
Player.record_old = {}
end

Event.Register("onGameEnd", onGameEnd)
Expand Down

0 comments on commit 6aea8c8

Please sign in to comment.