Jump to content

Recommended Posts

So basically my character will have the ability to eat "bad foods" as regular food, but at a cost to sanity.

The oneat() function so far is below:

local function oneat(inst, food)	Bad = {"monstermeat","cookedmonstermeat","green_cap","red_cap","blue_cap"}	for k, v in pairs(Bad) do		if food and food.components.edible and food.components.name == v then        inst.components.sanity:DoDelta(TUNING.SANITY_TINY * 2)				else			end    endend

My issue is that when I do eat monster meats, the sanity bonus (its a positive number now as a test) won't register, and I'm curious why that is. Is it the way I have it searching the list? or is the 3rd condition of

food.components.name == v 

that is causing the problem? I haven't used Lua in a few years and I think those might be it. 

You're looking to match v against food.prefab, rather than food.components.name.

 

Prefabs have the property prefab, which is a string containing the name of the prefab, as well as the property name, which is a string containing the display name of the prefab(which is not necessarily unique).

 

The food component has neither of these properties.

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...