. . . Posted May 12, 2019 Share Posted May 12, 2019 Hello, I want to know if it's possible to use tuning for something like this code ! When I use it now it doesn't seem to work or do anything. Spoiler local function Eat(inst, food) if TUNING.HOLHORSE_FOOD_FAVORITE[food.prefab] then inst.components.talker:Say("Just like back in Texas!") end end --masterpostinit inst.components.eater:SetOnEatFn(Eat) --modmain TUNING.HOLHORSE_FOOD_FAVORITE ={"hotchili",} Thanks for your time and help, have a great day ! Link to comment Share on other sites More sharing options...
Ultroman Posted May 12, 2019 Share Posted May 12, 2019 It should, but I don't think you can ask a list if it contains something that way. You'd have to employ a function like this: local function contains(mytable, value) if mytable and value then for _, v in ipairs(mytable) do if v == value then return true end end end return false end Link to comment Share on other sites More sharing options...
. . . Posted May 13, 2019 Author Share Posted May 13, 2019 Thank you! How exactly would I use this code and where would it be put in? The characterprefab or modmain? Is this how you use the code? Spoiler mytable = {"hotchili,"} local function contains(mytable, value) if mytable and value then for _, v in ipairs(mytable) do if v == value then return true end end end return false end if contains[food.prefab] then inst.components.talker:Say("Just like back in Texas!") end Link to comment Share on other sites More sharing options...
Ultroman Posted May 13, 2019 Share Posted May 13, 2019 Almost. "contains" is a function, so you don't use square brackets. Just call it. contains(mytable, food.prefab) If it returns true, then it found parameter 2 (object e.g. a string) in parameter 1 (a table). You can put the function in any LUA file where you want to use it. You could also make a separate LUA for all your utility functions such as this one, e.g. myutils.lua, and import it in the script files where you want to use it, by injecting it using e.g. require("myutils.lua"). Link to comment 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