diff options
author | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2017-12-25 20:46:49 +0100 |
---|---|---|
committer | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2017-12-25 20:46:49 +0100 |
commit | bac6157ffb37f2e67d713ca14eca23adb1a85f55 (patch) | |
tree | 5ef7f3a7bc90186bac02b1b0a22e484d4cd70630 | |
parent | 8d1f2d3b55cc4bde79a912fb167bd42ef2da42bc (diff) |
Make state persistent
-rw-r--r-- | init.lua | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -85,16 +85,27 @@ end function boat.on_activate(self, staticdata, dtime_s) - self.object:set_armor_groups({immortal = 1}) - if staticdata then - self.v = tonumber(staticdata) - end - self.last_v = self.v + self.object:set_armor_groups({immortal = 1}) + local data = {} + if staticdata then + data = minetest.deserialize(staticdata) + if not data then + return + end + + self.v = data.v + self.instructions = data.instr + self.selfdriving = data.sdr + self.dnext = data.dn + self.current = data.cur + end + self.last_v = self.v end function boat.get_staticdata(self) - return tostring(self.v) + data = {v = self.v, instr = self.instructions, cur = self.current, sdr = self.selfdriving, dn = self.dnext} + return minetest.serialize(data) end |