maliblues Posted March 4, 2020 Share Posted March 4, 2020 Using the hideout component I simply wanted to set a "OnGoHome" function. inst:AddComponent("hideout") inst.components.hideout:SetGoHomeFn(OnGoHome) The function set doesn't run since I always get the error "scripts/components/hideout.lua"]:187: variable 'count' is not declared" so I can link it back to the following from the component: function Hideout:GoHome( child ) if self.storedcreatures[child] ~= nil then print("Ack! We already have this child inside!?") return end self.storedcreatures[child] = child self.numstoredcreatures = GetTableSize(self.storedcreatures) child:RemoveFromScene() child.Transform:SetPosition(0,0,0) if child.components.brain then BrainManager:Hibernate(child) end if child.SoundEmitter then child.SoundEmitter:KillAllSounds() end if self.ongohome then self.ongohome(self.inst, count) end if self.numstoredcreatures == 1 and self.onoccupied then self:onoccupied(self.inst) end end But I'm still unsure what it is that I'm missing for it to run. I've tried guessing but have had no luck. I was wondering if it was even intended for "count" to be here. From what I can find only the cavelight prefab uses this component and doesn't use this gohome function either. Any help is appreciated Link to comment Share on other sites More sharing options...
CarlZalph Posted March 5, 2020 Share Posted March 5, 2020 (edited) 4 hours ago, maliblues said: But I'm still unsure what it is that I'm missing for it to run. I've tried guessing but have had no luck. I was wondering if it was even intended for "count" to be here. From what I can find only the cavelight prefab uses this component and doesn't use this gohome function either. Any help is appreciated You're right and this is a bug, please do report it in the bug tracker. A workaround is to make your own hook and callback for it: inst:AddComponent("hideout") local GoHome_old = inst.components.hideout.GoHome inst.components.hideout.GoHome = function(self, child, ...) local retval = GoHome_old(self, child, ...) -- Your code for "OnGoHome" event here return retval end You can make it call your other function if need be. Reason for the three dots and return value is to help futureproof your hook in case Klei changes things around. To solidify it futher is to put the return values from the _old function in a table and return an unpack function call, but I digress. Edited March 5, 2020 by CarlZalph 1 Link to comment Share on other sites More sharing options...
maliblues Posted March 5, 2020 Author Share Posted March 5, 2020 Thank you for the response! and the workaround is very helpful to know as well. Link to comment 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