Jump to content

Trying to figure out SetDiet


K-vo

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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"}
 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...