JChanger Posted June 23, 2024 Share Posted June 23, 2024 (edited) this mod is the packing box that can move structure(first pack, then move to sp, finally unpack), modified by myself. lots of people comment to me that when the game rollback to the previous save, the action of the unpack is misfunctional. After reviewing the code, i guess is the data do not restore when onload, so has impact on the unpack action. here is the code of save part: function Package:OnSave() return { content = self.content ~= nil and self.content.GUID or nil, }, { self.content ~= nil and self.content.GUID or nil, } end function Package:LoadPostPass(newents, savedata) if savedata.content ~= nil then local content = newents[savedata.content] if content ~= nil then self.content = content.entity end end end -- rewrite the save/load code above, 'cause the rollback bug? content is the entity of structure being packed. and here is the misfunctional action of unpack (seems the content is nil after rollback), this function exit on the first "return" or even return on the first "if" local UNPACK = AddAction("UNPACK", "Unpack", function(act) if act.target.components.package.content ~= nil then if act.target.components.burnable ~= nil then if act.target.components.burnable:IsBurning() or act.target.components.burnable:IsSmoldering() then return false end end -- JC: should use: CanDeployRecipeAtPoint? local recipe = GLOBAL.GetValidRecipe(act.target.components.package.content.prefab) if recipe ~= nil then local x, y, z = act.target.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, recipe.min_spacing, nil, 0, {"structure"}) if GLOBAL.next(ents) ~= nil then return false, "NOROOM" end end act.target.components.package:Unpack(act.doer) return true end end) UNPACK.priority = 4 i try a lot of times but cannot make the bug appear. Most people says like that, so it may not be unreal; Really appreciating to everybody's help and your time spent ! mode link is : https://steamcommunity.com/sharedfiles/filedetails/?id=2972042646 mod files are modmain.lua moving_box.lua package.lua Edited June 23, 2024 by JChanger Link to comment https://forums.kleientertainment.com/forums/topic/157450-component-data-is-nil-after-the-game-rollback/ Share on other sites More sharing options...
Haruhi Kawaii Posted June 23, 2024 Share Posted June 23, 2024 6 hours ago, JChanger said: this mod is the packing box that can move structure(first pack, then move to sp, finally unpack), modified by myself. lots of people comment to me that when the game rollback to the previous save, the action of the unpack is misfunctional. After reviewing the code, i guess is the data do not restore when onload, so has impact on the unpack action. here is the code of save part: function Package:OnSave() return { content = self.content ~= nil and self.content.GUID or nil, }, { self.content ~= nil and self.content.GUID or nil, } end function Package:LoadPostPass(newents, savedata) if savedata.content ~= nil then local content = newents[savedata.content] if content ~= nil then self.content = content.entity end end end -- rewrite the save/load code above, 'cause the rollback bug? content is the entity of structure being packed. and here is the misfunctional action of unpack (seems the content is nil after rollback), this function exit on the first "return" or even return on the first "if" local UNPACK = AddAction("UNPACK", "Unpack", function(act) if act.target.components.package.content ~= nil then if act.target.components.burnable ~= nil then if act.target.components.burnable:IsBurning() or act.target.components.burnable:IsSmoldering() then return false end end -- JC: should use: CanDeployRecipeAtPoint? local recipe = GLOBAL.GetValidRecipe(act.target.components.package.content.prefab) if recipe ~= nil then local x, y, z = act.target.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, recipe.min_spacing, nil, 0, {"structure"}) if GLOBAL.next(ents) ~= nil then return false, "NOROOM" end end act.target.components.package:Unpack(act.doer) return true end end) UNPACK.priority = 4 i try a lot of times but cannot make the bug appear. Most people says like that, so it may not be unreal; Really appreciating to everybody's help and your time spent ! mode link is : https://steamcommunity.com/sharedfiles/filedetails/?id=2972042646 mod files are modmain.lua 23.12 kB · 0 downloads moving_box.lua 8.16 kB · 0 downloads package.lua 9.18 kB · 0 downloads That bug appears when you put it in the backpack, I'm not good at coding so I can't help further 2024-06-23 21-54-45.mp4 Link to comment https://forums.kleientertainment.com/forums/topic/157450-component-data-is-nil-after-the-game-rollback/#findComment-1728501 Share on other sites More sharing options...
JChanger Posted June 25, 2024 Author Share Posted June 25, 2024 On 6/23/2024 at 10:58 PM, Haruhi Kawaii said: That bug appears when you put it in the backpack, I'm not good at coding so I can't help further 2024-06-23 21-54-45.mp4 thanks for offering help, i'll try it this weekend~ again lots of thanks~ Link to comment https://forums.kleientertainment.com/forums/topic/157450-component-data-is-nil-after-the-game-rollback/#findComment-1729059 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