josra102 Posted March 25, 2024 Share Posted March 25, 2024 Hello. After a short break, I continue working on the mod. According to the idea, during an action, a number, possibly one, is entered into the component, and when one is present, the character is given a tag. It seems that I dug up the code from the “hunger” component, but I don’t know what doesn’t work in it. I think there are several reasons for this 1.There is no way to write down the number 2.To save 3.In component inspection Component : local metalscrapknowledge = Class(function(self, inst) self.inst = inst self.max = 1 self.current = self.max, end) function metalscrapknowledge:SetMax(amount) self.max = amount self.current = amount end function metalscrapknowledge:DoDelta(delta) if self.redirect ~= nil then self.redirect(self.inst, delta) return end end function metalscrapknowledge:OnLoad(data) if data.metalscrapknowledge ~= nil and self.current ~= data.metalscrapknowledge then self.current = data.metalscrapknowledge self:DoDelta(0) end end function metalscrapknowledge:OnSave() return self.current ~= self.max and { metalscrapknowledge = self.current } or nil end return metalscrapknowledge Character : inst:AddComponent("metalscrapknowledge") print(inst.components.metalscrapknowledge) if inst.components.metalscrapknowledge == 1 then inst:AddTag("evgens_craft_plus") end end) If you know how to do this please write Link to comment https://forums.kleientertainment.com/forums/topic/155211-need-help-saving-the-value-of-a-component/ Share on other sites More sharing options...
_zwb Posted March 25, 2024 Share Posted March 25, 2024 Data in OnLoad could be nil, check that first maybe? Link to comment https://forums.kleientertainment.com/forums/topic/155211-need-help-saving-the-value-of-a-component/#findComment-1707518 Share on other sites More sharing options...
josra102 Posted March 31, 2024 Author Share Posted March 31, 2024 It works! I think there was a problem that the data names were different local metalscrapknowledge = Class(function(self, inst) self.inst = inst self.current = 0 end) function metalscrapknowledge:Set(amount) self.current = amount end function metalscrapknowledge:Get() return self.current end function metalscrapknowledge:OnSave() return self.current and { metalscrapknowledge = self.current } or nil end function metalscrapknowledge:OnLoad(data) if data.metalscrapknowledge ~= nil and self.current ~= data.metalscrapknowledge then self.current = data.metalscrapknowledge end end return metalscrapknowledge Link to comment https://forums.kleientertainment.com/forums/topic/155211-need-help-saving-the-value-of-a-component/#findComment-1708800 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