[0.8.9][NK] Save System

johnycilohoklajohnycilohokla REGISTERED Posts: 283 Developer
edited December 2015 in Modding Tutorials

Save System

Save system is TUG uses tables to save and restore data.
This is done using 2 functions, Save and Restore exposed on GameObjects and Mods (ModScriptClass).

Allowed types

  • Number
  • String
  • Vec3
  • Quat
  • GameObject
  • LuaTable

Important: to iterate LuaTable you will have to use pairs, ipairs will not work!

Class

Save Example:
function Equipable:Save( outData )
Equipable.__super.Save(self, outData) -- call Save from super (parent) Class

outData.maxDurability = self:GetMaxHitPoints() -- save the max durability
outData.currentDurability = self:GetHitPoints() -- save the durability
end
Restore Example:
function Equipable:Restore( inData, version )
Equipable.__super.Restore(self, inData) -- call Restore from super (parent) Class

self:SetMaxHitPoints(inData.maxDurability) -- load the max durability
self:SetHitPoints(inData.currentDurability) -- load the durability
self.m_restored = true -- set the m_restored to true (used internally)
end

Mixins

Save Example:
function ConsumesFuel:Save(outData)
outData.fuelTimer = self.m_fuelTimer -- save fuel time
end
Restore Example:
function ConsumesFuel:Restore(inData, version)
if(inData.fuelTimer ~= nil) then -- make sure the variable exists
self.m_fuelTimer = inData.fuelTimer -- load fuel time
end
end
My Blog
jc.png
  yt.png  t.png  
Sign In or Register to comment.