Jump to content

Recommended Posts

I'm working on a character that is supposed to be able to eat pretty much anything as their hunger drops VERY fast. I'm wanting to enable all the foodtypes outside of Omni as well but for the life of me I can't get the setdiet and some of the eater settings to work, it either freezes my game when I implement it or doesn't seem to enable. I'm pretty new to Lua, so I'm probably missing something really obvious. Am I correct in thinking that it's supposed to go in the character prefab?

05e9520a1898ae95c56ca947bf0318ed.png

 

This is what I've got right now.

Here's the error log @whismerhill, It just seems to crash straight out, no error message.

And @Mobbstar good to know. I've also tried inst.components.eater.foodprefs but perhaps I'm incorrectly doing syntax? I'm not really sure.

Thank you for taking the time to look.

log.txt

This code is DST-specific, but your mod is trying to run in DS.

Set the table directly, for example: inst.components.eater.foodprefs = {"GENERIC", "SEEDS", "MEAT", "ETC"}

Also, update the API version as set in modinfo.lua, the current one is 6 for DS and 10 for DST

I've done as you said, and while it's no longer crashing, it seems to be having no effect at all on what the character can eat. It seems to be defaulting to basic omnivore.
 

I used inst.components.eater.foodprefs = {"GENERIC", "SEEDS", "MEAT", "HORRIBLE", "ELEMENTAL", "INSECT", "VEGGIE", "WOOD"}
 

As an information this is what was important in the log file:

 

Spoiler

 


...data/../mods/wickerman/scripts/prefabs/wickerman.lua:73: variable 'FOODGROUP' is not declared
LUA ERROR stack traceback:
=[C]:-1 in (global) error (C) <-1--1>
E:/SteamLibrary/steamapps/common/dont_starve/data/scripts/strict.lua:23 in () ? (Lua) <21-26>
   t = table: 117FA738
   n = FOODGROUP
E:/SteamLibrary/steamapps/common/dont_starve/data/../mods/wickerman/scripts/prefabs/wickerman.lua:73 in (upvalue) customfn (Lua) <41-86>
   inst = 100030 -  (valid:true)
E:/SteamLibrary/steamapps/common/dont_starve/data/scripts/prefabs/player_common.lua:573 in (field) fn (Lua) <227-577>
   Sim = Sim (0E4CD010)
   inst = 100030 -  (valid:true)

 

 

a few times, some of the content that follows can be important, but mostly the first line is your problem. notice how it's just before "TRACEBACK", always is...

Thank you for that explanation of the log file! Also I've been looking at the eater.lua file and it seems all the diets correspond to things like
Eater:SetOmnivore(), Eater:SetBeaver(), Eater:SetBird(), etc.

the functions look like: 

function Eater:SetVegetarian()
    self.foodprefs = { "VEGGIE" }
end

Maybe creating a new eater type might work? I apologize for my noobness.

I am not an expert but indeed that seems like a good idea.

maybe something with AddComponentPostInit

which would add a new function something like this

function Eater:InsertCanEat(data)
	table.insert(self.foodprefs, data) -- where data is any foodtype (copied from setcaneat horrible)
end

-- or alternatively

function Eater:SetCanEatEverything()
	self.foodprefs = {"ELEMENTAL", ... }
end

 

I tried inputting this into modmain

AddComponentPostInit("setcaneateverything",
function (eater, inst) Eater:SetCanEatEverything()
    self.foodprefs = {"ELEMENTAL", "GENERIC", "HORRIBLE", "SEEDS", "INSECT", "VEGGIE", "MEAT", "WOOD" }
end
)

but when I place

inst.components.eater:SetCanEatEverything("ELEMENTAL", "GENERIC", "HORRIBLE", "SEEDS", "INSECT", "VEGGIE", "MEAT", "WOOD" )

in the character file it says I'm calling a nil value. It did that when I placed 

inst.components.eater:SetCanEatEverything() 

as well.

1 hour ago, K-vo said:

I tried putting this into modmain

The arguments are wrong, try this:

AddComponentPostInit("eater",
function (self) self:SetCanEatEverything()
    self.foodprefs = {"ELEMENTAL", "GENERIC", "HORRIBLE", "SEEDS", "INSECT", "VEGGIE", "MEAT", "WOOD" }
end
)

@mobbstar Thank you! I put that in. Currently the issue seems to be the line in the character prefab according to this in the log:

...data/../mods/wickerman/scripts/prefabs/wickerman.lua:73: attempt to call method 'SetCanEatEverything' (a nil value)

which in that line is:

inst.components.eater:SetCanEatEverything() 

How would I callback to the new eater function in the character prefab otherwise?
Thanks again for your patience and assistance! It's much appreciated.

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