. . . Posted September 7, 2017 Share Posted September 7, 2017 (edited) Hello, I need help fixing a crash if someone can help me that'd be great ! 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 ! Edited September 10, 2017 by SuperDavid Link to comment https://forums.kleientertainment.com/forums/topic/81806-solved-need-help-fixing-crash-components-nil-value/ Share on other sites More sharing options...
Lumina Posted September 7, 2017 Share Posted September 7, 2017 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 ! Is it the same perk than WX-78 ? If yes you could look at his files. Link to comment https://forums.kleientertainment.com/forums/topic/81806-solved-need-help-fixing-crash-components-nil-value/#findComment-951111 Share on other sites More sharing options...
. . . Posted September 7, 2017 Author Share Posted September 7, 2017 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 https://forums.kleientertainment.com/forums/topic/81806-solved-need-help-fixing-crash-components-nil-value/#findComment-951114 Share on other sites More sharing options...
JohnWatson Posted September 7, 2017 Share Posted September 7, 2017 What's the crash report Link to comment https://forums.kleientertainment.com/forums/topic/81806-solved-need-help-fixing-crash-components-nil-value/#findComment-951300 Share on other sites More sharing options...
. . . Posted September 7, 2017 Author Share Posted September 7, 2017 attempt to index field 'components' (a nil value) at local food_hungervalue = food.components.edible.hungervalue Link to comment https://forums.kleientertainment.com/forums/topic/81806-solved-need-help-fixing-crash-components-nil-value/#findComment-951381 Share on other sites More sharing options...
. . . Posted September 9, 2017 Author Share Posted September 9, 2017 bump Link to comment https://forums.kleientertainment.com/forums/topic/81806-solved-need-help-fixing-crash-components-nil-value/#findComment-951734 Share on other sites More sharing options...
Cunning fox Posted September 9, 2017 Share Posted September 9, 2017 Spoiler if food.components ~= nil then 1 Link to comment https://forums.kleientertainment.com/forums/topic/81806-solved-need-help-fixing-crash-components-nil-value/#findComment-951795 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