Parusoid Posted January 8, 2019 Share Posted January 8, 2019 what can be the reason of data not loading properly? i have an fueled item, and whenever it is at full fuel, and relog is done, fuel level is reset even tho there are onsave and onload functions local function onsave(inst, data) return {fuel = inst.components.fueled.currentfuel} end local function onload(inst, data) if data.fuel ~= nil then inst.components.fueled:InitializeFuelLevel(math.max(0, data.fuel)) end end Link to comment Share on other sites More sharing options...
Developer bizziboi Posted January 9, 2019 Developer Share Posted January 9, 2019 Did you set the functions on the prefab? inst.OnSave = onsave inst.OnLoad = onload Link to comment Share on other sites More sharing options...
Parusoid Posted January 9, 2019 Author Share Posted January 9, 2019 1 minute ago, bizziboi said: Did you set the functions on the prefab? inst.OnSave = onsave inst.OnLoad = onload yes i did Link to comment Share on other sites More sharing options...
Developer bizziboi Posted January 9, 2019 Developer Share Posted January 9, 2019 Hmmmm, seems your save doesn't work as I normally see it, it sets items on data, it doesn't return it (the function is supposed to return any entities this entity references in its save data, not the save data itself). Maybe more something like local function onsave(inst, data) data.fuel = inst.components.fueled.currentfuel end Link to comment Share on other sites More sharing options...
YakumoYukari Posted January 9, 2019 Share Posted January 9, 2019 The way you have done is for components. here's a simple example in basalt.lua local function onsave(inst, data) data.anim = inst.animname end local function onload(inst, data) if data and data.anim then inst.animname = data.anim inst.AnimState:PlayAnimation(inst.animname) end end Link to comment Share on other sites More sharing options...
Parusoid Posted January 9, 2019 Author Share Posted January 9, 2019 13 minutes ago, bizziboi said: Hmmmm, seems your save doesn't work as I normally see it, it sets items on data, it doesn't return it (the function is supposed to return any entities this entity references in its save data, not the save data itself). Maybe more something like local function onsave(inst, data) data.fuel = inst.components.fueled.currentfuel end This one works, thanks. It was interesting that the fuel level was not saved only when it was at 100% (other levels were saved with no issues). As i looked into the fueled component it turns out that it only saves if the level is different than 100% as seen below: Spoiler function Fueled:OnSave() if self.currentfuel ~= self.maxfuel then return {fuel = self.currentfuel} end end Im assuming it is beacuse when it is at 100% then InitializeFuelLevel will handle this in 'create entity' part. However my item initializes with fuel equal to 0 (unlike all other fueled items in the game), so it seem like this component does not handle custom InitializeFuelLevel (other than maxfuel). Link to comment Share on other sites More sharing options...
YakumoYukari Posted January 9, 2019 Share Posted January 9, 2019 https://github.com/HimekaidouHatate/YakumoYukari-DST/blob/master/scripts/prefabs/yukarihat.lua you could see my code and reference how I initialize component. Or in this case, it's best to do create your own component(see spellcard.lua in component in my mod). 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