Jump to content

Recommended Posts

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 by Anstarveo
--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 by Aquaterion

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...