loopuleasa Posted August 4, 2023 Share Posted August 4, 2023 Hi, I am looking into updating the eat your veggies mod, and it would be very useful if I could get the prefab from a string, like "barnaclepita" Is this doable? Has anyone done such a function before? Link to comment https://forums.kleientertainment.com/forums/topic/150162-is-a-getfoodbyname-function-possible/ Share on other sites More sharing options...
_zwb Posted August 4, 2023 Share Posted August 4, 2023 What do you mean by "get the prefab"? Spawn one in? Link to comment https://forums.kleientertainment.com/forums/topic/150162-is-a-getfoodbyname-function-possible/#findComment-1657107 Share on other sites More sharing options...
loopuleasa Posted August 4, 2023 Author Share Posted August 4, 2023 sadly picky eater mod is not using prefabs, just tracking a list of food names if food you are about to eat.name ~= allowed food name, then you are not allowed to eat I want to be able to check properties via food name only updated eat your veggies mod for modern recipes and warly https://steamcommunity.com/sharedfiles/filedetails/?id=3014792878 had to implement it the hard way sadly Link to comment https://forums.kleientertainment.com/forums/topic/150162-is-a-getfoodbyname-function-possible/#findComment-1657124 Share on other sites More sharing options...
_zwb Posted August 4, 2023 Share Posted August 4, 2023 (edited) 37 minutes ago, loopuleasa said: sadly picky eater mod is not using prefabs, just tracking a list of food names if food you are about to eat.name ~= allowed food name, then you are not allowed to eat I want to be able to check properties via food name only updated eat your veggies mod for modern recipes and warly https://steamcommunity.com/sharedfiles/filedetails/?id=3014792878 had to implement it the hard way sadly isn't it easier to just do local allowed_foods = {"meat", "banana"} -- a table containing allowed foods' prefab names local function CanEatTest(food) for k,v in pairs(allowed_foods) if v == food.prefab then return true end return false end why would you use the food's actual name rather than prefab name? or you can do this: foods = {} for _,v in pairs({"meat", "banana",}) do -- all the foods you allow to eat foods[v] = true end local function CanEatTest(food) return foods[food.prefab] end Edited August 4, 2023 by _zwb Link to comment https://forums.kleientertainment.com/forums/topic/150162-is-a-getfoodbyname-function-possible/#findComment-1657139 Share on other sites More sharing options...
loopuleasa Posted August 4, 2023 Author Share Posted August 4, 2023 1 hour ago, _zwb said: isn't it easier to just do local allowed_foods = {"meat", "banana"} -- a table containing allowed foods' prefab names local function CanEatTest(food) for k,v in pairs(allowed_foods) if v == food.prefab then return true end return false end why would you use the food's actual name rather than prefab name? or you can do this: foods = {} for _,v in pairs({"meat", "banana",}) do -- all the foods you allow to eat foods[v] = true end local function CanEatTest(food) return foods[food.prefab] end I am using prefab name, but as string. for instance "barnaclepita" the problem is that it is in a string format, and I don't know if I can access properties (like meat or veg value) the mod has been updated but I have duplicated the lists for wurt and wigfrid https://steamcommunity.com/sharedfiles/filedetails/?id=3014792878 Link to comment https://forums.kleientertainment.com/forums/topic/150162-is-a-getfoodbyname-function-possible/#findComment-1657156 Share on other sites More sharing options...
Rickzzs Posted August 4, 2023 Share Posted August 4, 2023 Spawn one and then remove it. Link to comment https://forums.kleientertainment.com/forums/topic/150162-is-a-getfoodbyname-function-possible/#findComment-1657170 Share on other sites More sharing options...
_zwb Posted August 4, 2023 Share Posted August 4, 2023 (edited) 43 minutes ago, loopuleasa said: he problem is that it is in a string format, and I don't know if I can access properties (like meat or veg value) You can access that by requiring the preparedfoods.lua file local require = GLOBAL.require local preparedfoods = require("preparedfoods") local preparedfoods_warly = require("preparedfoods_warly") local food_list = {} for k,v in pairs(preparedfood_list) do table.insert(food_list, {k, v.foodtype}) end for k,v in pairs(preparedfood_list_warly) do table.insert(food_list, {k, v.foodtype}) end 2 minutes ago, Rickzzs said: Spawn one and then remove it. I bet there would be random food items spawning at (0,0,0) Edited August 4, 2023 by _zwb Link to comment https://forums.kleientertainment.com/forums/topic/150162-is-a-getfoodbyname-function-possible/#findComment-1657171 Share on other sites More sharing options...
Rickzzs Posted August 5, 2023 Share Posted August 5, 2023 7 hours ago, _zwb said: I bet there would be random food items spawning at (0,0,0) Just inspired by this. Link to comment https://forums.kleientertainment.com/forums/topic/150162-is-a-getfoodbyname-function-possible/#findComment-1657247 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