Make state persistent
parent
8d1f2d3b55
commit
bac6157ffb
23
init.lua
23
init.lua
|
@ -85,16 +85,27 @@ end
|
||||||
|
|
||||||
|
|
||||||
function boat.on_activate(self, staticdata, dtime_s)
|
function boat.on_activate(self, staticdata, dtime_s)
|
||||||
self.object:set_armor_groups({immortal = 1})
|
self.object:set_armor_groups({immortal = 1})
|
||||||
if staticdata then
|
local data = {}
|
||||||
self.v = tonumber(staticdata)
|
if staticdata then
|
||||||
end
|
data = minetest.deserialize(staticdata)
|
||||||
self.last_v = self.v
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
function boat.get_staticdata(self)
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue