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 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.