Jump to content

Recommended Posts

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

 

  • Developer

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

 

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

 

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).

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).

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...