Anstarveo Posted March 17, 2017 Share Posted March 17, 2017 (edited) local forbidden = {eggplant = true, eggplant_cooked = true, stuffedeggplant = true} local _PrefersToEat = inst.components.eater.PrefersToEat inst.components.eater.PrefersToEat = function(self, food) return _PrefersToEat(self, food) and not forbidden[food.prefab] end The code is about refusing to eat a few certain things. Can someone clarifies line 2->4? Especially line 4 Edited March 18, 2017 by Anstarveo Link to comment https://forums.kleientertainment.com/forums/topic/76258-solved-need-clarification-for-a-few-line-of-codes/ Share on other sites More sharing options...
Aquaterion Posted March 17, 2017 Share Posted March 17, 2017 (edited) --i renamed the _PrefersToEat variable to make it slightly clearer local oldPrefersToEatFn = inst.components.eater.PrefersToEat --store the PrefersToEat function in the oldPrefersToEatFn variable inst.components.eater.PrefersToEat = function(self, food) --set the PrefersToEat function, without modifying the oldPrefersToEatFn variable return oldPrefersToEatFn(self, food) and not forbidden[food.prefab] --Make the NEW PrefersToEat function return true or false depending on --both oldPrefersToEatFn's return value and whether or not food.prefab --exists in forbidden table. end --So what this does is get the normal behaviour of PrefersToEat which is --stored in OldPrefersToEatFn while also checking if the forbidden food is not true. --using the AND operator, it returns the correct boolean. Edited March 17, 2017 by Aquaterion Link to comment https://forums.kleientertainment.com/forums/topic/76258-solved-need-clarification-for-a-few-line-of-codes/#findComment-885725 Share on other sites More sharing options...
Anstarveo Posted March 17, 2017 Author Share Posted March 17, 2017 Wow! Thanks to you my brain is able to digest it now. Link to comment https://forums.kleientertainment.com/forums/topic/76258-solved-need-clarification-for-a-few-line-of-codes/#findComment-885995 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