Nappy Posted February 17, 2021 Share Posted February 17, 2021 As you can see from the title, I am running into a problem when editing a component function using postInIt(). What I am trying to change is components/weapon:CollectEquippableActions(...) because I need to remove the IsAlly test. This is what the function looks like in the don't starve weapon file... function Weapon:CollectEquippedActions(doer, target, actions) if doer.components.combat and not target:HasTag("wall") and doer.components.combat:CanTarget(target) and target.components.combat:CanBeAttacked(doer) and not doer.components.combat:IsAlly(target) and (not self.canattack or self.canattack(self.inst, target) ) then table.insert(actions, ACTIONS.ATTACK) end end And what I did was port this function to my modmain and make this adjustment... AddComponentPostInit("weapon", function(self) local oldfunction1 = self.CollectEquippedActions -- Keep the old function in case we need it later. function self:CollectEquippedActions(doer, target, actions) if self.inst:HasTag("myweapon") and target:HasTag("rocky") and not target:HasTag("rocky_k") and doer.components.combat and not target:HasTag("wall") and doer.components.combat:CanTarget(target) and target.components.combat:CanBeAttacked(doer) -- and not doer.components.combat:IsAlly(target) and (not self.canattack or self.canattack(self.inst, target) ) then table.insert(actions, ACTIONS.ATTACK) elseif doer.components.combat and not target:HasTag("wall") and doer.components.combat:CanTarget(target) and target.components.combat:CanBeAttacked(doer) and not doer.components.combat:IsAlly(target) and (not self.canattack or self.canattack(self.inst, target) ) then table.insert(actions, ACTIONS.ATTACK) end end end) I have tried.. #1) the above giving me attempt to index global 'ACTIONS' (a nil value) #2) placing local actions = GLOBAL.ACTIONS in my modmain which gives me attempt to index global 'ACTIONS' (a nil value) #3) table.insert(GLOBAL.actions, ACTIONS.ATTACK) which gives me variable actions is not declared. I don't want to just put the component file in my mod because of compatibility problems. What am I missing? I bet it is something super simple... Link to comment https://forums.kleientertainment.com/forums/topic/127144-editing-component-functions-with-table-references-via-postinit/ Share on other sites More sharing options...
penguin0616 Posted February 19, 2021 Share Posted February 19, 2021 On 2/16/2021 at 11:10 PM, Nappy said: placing local actions = GLOBAL.ACTIONS local ACTIONS = GLOBAL.ACTIONS Variable capitalization matters. 1 Link to comment https://forums.kleientertainment.com/forums/topic/127144-editing-component-functions-with-table-references-via-postinit/#findComment-1430821 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