Atena Posted March 7, 2015 Share Posted March 7, 2015 I write code to try save item data to disk and hope read this data next booting, but seem this data don't save successfully. I couldn't read save data at reboot, why? My code following:function container:Open(doer) -- Try to load last save data inst.OnLoad = onload -- If last data(inst.lockID) is empty, save opener userid to inst data if inst.lockID == "" then inst.lockID = doer.userid -- Save Data inst.OnSave = onsave -- Reload Data inst.OnLoad = onload return nil end end-- Save Datalocal function onsave(inst, data) data.lockID = inst.lockIDend-- Load Datalocal function onload(inst, data) if data and data.lockID then inst.lockID = data.lockID end endBut seems data don't save, I restart serevr and trace first reload data, inst.lockid was still empty. Link to comment Share on other sites More sharing options...
DarkXero Posted March 7, 2015 Share Posted March 7, 2015 What is container? A prefab? Or are you trying to edit the container component?OnLoad and OnSave don't get executed whenever you write the line, they get executed when loading and saving.AddComponentPostInit("container", function(self) self.lockID = nil local old1 = self.Open function self:Open(doer) if self.lockID == nil then self.lockID = doer.userid end old1(self, doer) end local old2 = self.OnSave function self:OnSave() local data = {} data.lockID = self.lockID data.olddata = old2(self) return data end local old3 = self.OnLoad function self:OnLoad(data, newents) if data and data.lockID then self.lockID = data.lockID end if data and data.olddata then old3(self, data.olddata, newents) end endend)You have to override Open, OnSave, and OnLoad. Link to comment Share on other sites More sharing options...
greenglacier Posted March 7, 2015 Share Posted March 7, 2015 Mhm. I see. The code... It seems to be wrong *points* there, there and... here. Link to comment Share on other sites More sharing options...
Atena Posted March 13, 2015 Author Share Posted March 13, 2015 Thanks for your help, I am trying it now. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now