Jump to content

[SOlved] Need help fixing crash "components nil value"


Recommended Posts

Hello, I need help fixing a crash if someone can help me that'd be great :wilson_smile:!

So, when my character eats certain food I want him to gain sanity bonus because it's his favorite food. I want him to gain a sanity bonus which's based off of half of the food's hunger value. This is code I have right now in MYCHAR.lua & it causes crash..

Spoiler

local function Eat_Food(inst, food)
	local fp = food.prefab
	local ic = inst.components
	local food_hungervalue = food.components.edible.hungervalue
	
	local loved_foods =
	{
	fishsticks = true,
	}
	
	local hated_foods =
	{
	
	}
	
	if loved_foods[fp] then
		inst.components.sanity:DoDelta(food_hungervalue * .5)
		if inst.components.sanity:IsSane() then
			inst.components.talker:Say("Yum!")
		end
	end
end

-- inside masterpostinit
inst.components.eater:SetOnEatFn(Eat_Food)

 

specifically at this line of code at the "components" part saying it's a nil value, does anyone know why this is happening & how I can fix it?

local food_hungervalue = food.components.edible.hungervalue

 

I have one more thing I need help with it shouldn't be so difficult, basically I want my character to take no Sanity penalty from eating stale or spoiled food, does anyone know how I can do this too?   Thanks for reading my problems, have a great day/night :wilson_laugh:!

Edited by SuperDavid
Link to comment
Share on other sites

58 minutes ago, SuperDavid said:

I have one more thing I need help with it shouldn't be so difficult, basically I want my character to take no Sanity penalty from eating stale or spoiled food, does anyone know how I can do this too?   Thanks for reading my problems, have a great day/night :wilson_laugh:!

Is it the same perk than WX-78 ? If yes you could look at his files.

Link to comment
Share on other sites

4 minutes ago, Lumina said:

Is it the same perk than WX-78 ? If yes you could look at his files.

WX takes no penalty to hunger, health & sanity from stale or spoiled food, I just want to take no penalty from Sanity.

 

Link to comment
Share on other sites

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
 Share

×
  • Create New...