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.

Recommended Posts

MidrealmDM    102

Hello,
I have a mod which creates additional food items, however if I try to add spices to them using Warly's station, I end up with spiced wet goop.

I have looked at spicedfoods.lua and I cant see any reason for this, but admittedly my Lua knowledge is limited.
 

Spoiler

 

function GenerateSpicedFoods(foods)
    for foodname, fooddata in pairs(foods) do
        for spicenameupper, spicedata in pairs(SPICES) do
            local newdata = shallowcopy(fooddata)
            local spicename = string.lower(spicenameupper)
            if foodname == "wetgoop" then
                newdata.test = function(cooker, names, tags) return names[spicename] end
                newdata.priority = -10
            else
                newdata.test = function(cooker, names, tags) return names[foodname] and names[spicename] end
                newdata.priority = 100
            end
            newdata.cooktime = .12
            newdata.stacksize = nil
            newdata.spice = spicenameupper
            newdata.basename = foodname
            newdata.name = foodname.."_"..spicename
            spicedfoods[newdata.name] = newdata

            if spicedata.prefabs ~= nil then
                --make a copy (via ArrayUnion) if there are dependencies from the original food
                newdata.prefabs = newdata.prefabs ~= nil and ArrayUnion(newdata.prefabs, spicedata.prefabs) or spicedata.prefabs
            end

            if spicedata.oneatenfn ~= nil then
                if newdata.oneatenfn ~= nil then
                    local oneatenfn_old = newdata.oneatenfn
                    newdata.oneatenfn = function(inst, eater)
                        spicedata.oneatenfn(inst, eater)
                        oneatenfn_old(inst, eater)
                    end
                else
                    newdata.oneatenfn = spicedata.oneatenfn
                end
            end
        end
    end
end


GenerateSpicedFoods(require("preparedfoods"))
GenerateSpicedFoods(require("preparedfoods_warly"))

return spicedfoods

 

I had thought maybe adding
GenerateSpicedFoods(require("mod_foods"))

-- Insert modded_foods into food spicer
local function ModDSTSpicer(inst)
GenerateSpicedFoods(require("mod_foods"))
end

AddPrefabPostInit("spicedfoods", ModDSTSpicer)
 

However, this didn't result in any change, either because it doesn't matter, or perhaps is coded wrong.

I am at a bit of a loss.

Any advice would be appreciated, thank you.

Share this post


Link to post
Share on other sites
Ultroman    540

Well, it looks solid. Have you tried going extreme with debug prints, basically printing absolutely everything pertaining to the state for each line, to see exactly what happens and what doesn't happen as you want? I know it sounds tedious and I always suggest this, but it's how I always end up finding the solution to weird problems.

Share this post


Link to post
Share on other sites
IronHunter    355

I succeeded in doing this actually, what I did was store the table in a local variable, delete the duplicated contents and generate my own.

--"rewritten from memory, I don't have access to my computer at this time"
local spicedfoods = require("spicedfoods")
for k, v in pairs do
   spicesfoods[k] = nil
end
GenerateSpicedFoods(require("moddedspicedfood"))
return spicedfoods

This worked for me, it is possible I made a typo here as I don't have access to my mod files at this time.

Edit:

You sre going to want to place this in a seperate nonprefab file. That will be imported into your spicer addcookpotfood or something like that. As its technically a seperate crockpot.

I will upload my actual code when I get home.

Edit2: this spiced thing gave me a headache on release, as I had to completely rework my modded prepared foods to make them compatible with the icons, plates and garnish. I might as well upload all the code related to this later. As its not simply 1 section of code that needs updating but like 3 or 4 areas that need to be changed so that they aren't invisible, have their garnish and plates.

Share this post


Link to post
Share on other sites
MidrealmDM    102
10 hours ago, IronHunter said:

You sre going to want to place this in a seperate nonprefab file. That will be imported into your spicer addcookpotfood or something like that. As its technically a seperate crockpot.
 

I am not sure what you mean here....

Share this post


Link to post
Share on other sites
IronHunter    355
--modmain
local spicedfoods = require("rn_spicedfoods")
for k, recipe in pairs (spicedfoods) do
	AddCookerRecipe("portablespicer", recipe)
end

rn is just a abbreviation for my mod, it contains both caffeine and alcohol so you can ignore them. But they are not vanilla features, same with the drinksymbol as that uses my own custom drinking animation.

But this is my cookpotfood prefab and the spiced foods is a external file that is imported.

Obviously people will need to modify the files to make them for their mods, as it does contain extra data.

rn_spicedfoods.lua

rn_cookpotfood.lua

Edit:
I hope this helps, you should be able to figure out what I intended with the code I provided.

Share this post


Link to post
Share on other sites
MidrealmDM    102
22 hours ago, IronHunter said:

Edit:
I hope this helps, you should be able to figure out what I intended with the code I provided.

It does indeed.--

Ive made several modifications - but I am getting an error..
"[string "../mods/waiter-381565292/scripts/W101_cookp..."]:431: attempt to call global 'require' (a nil value)".

431: for k,v in pairs(require("W101_menu")) do
432:     prefs[#prefs+1] = MakePreparedFood(v)
433: end

I am not sure why I am getting an error, as it is the same as your example...

 

W101_cookpotfood.lua

Share this post


Link to post
Share on other sites
IronHunter    355

 

4 hours ago, MidrealmDM said:

It does indeed.--

Ive made several modifications - but I am getting an error..
"[string "../mods/waiter-381565292/scripts/W101_cookp..."]:431: attempt to call global 'require' (a nil value)".

431: for k,v in pairs(require("W101_menu")) do
432:     prefs[#prefs+1] = MakePreparedFood(v)
433: end

I am not sure why I am getting an error, as it is the same as your example...

This file is a prefab correct? That is the only thing I can think is a scope issue, as require should work when called as a prefab. I know in the modmain I used to need to local require = GLOBAL.require

Edit:
I just encountered a different issue for some reason my spiced foods doesn't appear on the portablespicer despite appearing correctly on the plates when on the ground or in the regular crockpot. Making me believe the basename isn't being passed properly...

Share this post


Link to post
Share on other sites
MidrealmDM    102
On 7/30/2019 at 12:53 AM, IronHunter said:

 

This file is a prefab correct?

oops..
I had them backwards - the cookpotfood.lua in scripts and the recipe list or 'W101_menu.lua' was in prefabs, after swapping them I got past that error.

Thank you,
However, although the spiced food items are in the game and can be loaded with debug command,

When I try to create them using the spice station, I end up with spiced wet goop.

image.png.bf5abb58664630d16cf7daead625b24d.png

 

Share this post


Link to post
Share on other sites
IronHunter    355

So I rewrote my rn_spicedfoods.lua since we last talked, because I was also getting some minor bugs. I have everything working but it showing up on the crockpot properly. Which is very frustrating. I am sharing what I got below.

I am able to spice everything including vanilla foods and custom ones using the spice pot but can't get the custom ones to show up on the plate.

my spicedfoods.lua is just sitting in my scripts folder

my cookpotfoods is a prefab

and the other code I provided was in the modmain

 

rn_spicedfoods.lua

Share this post


Link to post
Share on other sites
MidrealmDM    102
On 7/31/2019 at 8:03 PM, IronHunter said:

I am able to spice everything including vanilla foods and custom ones using the spice pot but can't get the custom ones to show up on the plate.

 

Thank you for your help,

I am having the same problem... the foods dont appear in warly's cookpot, nor at the spicing station.
From portablespicer.lua:

=====================================

local function ShowProduct(inst)
    if not inst:HasTag("burnt") then
        local product = inst.components.stewer.product
        local recipe = cooking.GetRecipe(inst.prefab, product)
        if recipe ~= nil then
            product = recipe.basename or product
            if recipe.spice ~= nil then
                inst.AnimState:OverrideSymbol("swap_plate", "plate_food", "plate")
                inst.AnimState:OverrideSymbol("swap_garnish", "spices", string.lower(recipe.spice))
            else
                inst.AnimState:ClearOverrideSymbol("swap_plate")
                inst.AnimState:ClearOverrideSymbol("swap_garnish")
            end
        else
            inst.AnimState:ClearOverrideSymbol("swap_plate")
            inst.AnimState:ClearOverrideSymbol("swap_garnish")
        end
        if IsModCookingProduct(inst.prefab, product) then -- this part appears to be trying to pull in a new image/animation
            inst.AnimState:OverrideSymbol("swap_cooked", product, product)
        else
            inst.AnimState:OverrideSymbol("swap_cooked", "cook_pot_food", product)
        end
    end
end

============================================

I can only conclude that it is not pulling the image correctly.

interestingly -
the cookpot.lua has the following
=====
   inst.AnimState:OverrideSymbol("swap_cooked", overridebuild or "cook_pot_food", product)
=====
and that seems to work...
But i'm at a loss

 

 

Share this post


Link to post
Share on other sites
IronHunter    355
1 hour ago, MidrealmDM said:

Thank you for your help,

I am having the same problem... the foods dont appear in warly's cookpot, nor at the spicing station.
From portablespicer.lua:

=====================================

local function ShowProduct(inst)
    if not inst:HasTag("burnt") then
        local product = inst.components.stewer.product
        local recipe = cooking.GetRecipe(inst.prefab, product)
        if recipe ~= nil then
            product = recipe.basename or product
            if recipe.spice ~= nil then
                inst.AnimState:OverrideSymbol("swap_plate", "plate_food", "plate")
                inst.AnimState:OverrideSymbol("swap_garnish", "spices", string.lower(recipe.spice))
            else
                inst.AnimState:ClearOverrideSymbol("swap_plate")
                inst.AnimState:ClearOverrideSymbol("swap_garnish")
            end
        else
            inst.AnimState:ClearOverrideSymbol("swap_plate")
            inst.AnimState:ClearOverrideSymbol("swap_garnish")
        end
        if IsModCookingProduct(inst.prefab, product) then -- this part appears to be trying to pull in a new image/animation
            inst.AnimState:OverrideSymbol("swap_cooked", product, product)
        else
            inst.AnimState:OverrideSymbol("swap_cooked", "cook_pot_food", product)
        end
    end
end

============================================

I can only conclude that it is not pulling the image correctly.

interestingly -
the cookpot.lua has the following
=====
   inst.AnimState:OverrideSymbol("swap_cooked", overridebuild or "cook_pot_food", product)
=====
and that seems to work...
But i'm at a loss

 

 

Ya it works for the cookpot not for the spicepot. Np I am glad I could help save you a bunch of time so far. I was hoping our two heads could fix this animation bug for the spice pot. For now I have just extended the stewer functions that relate to the animations to get it to show. But I was hoping there was a better way to do it.

Share this post


Link to post
Share on other sites
MidrealmDM    102
On 8/3/2019 at 9:59 PM, IronHunter said:

Ya it works for the cookpot not for the spicepot. Np I am glad I could help save you a bunch of time so far. I was hoping our two heads could fix this animation bug for the spice pot. For now I have just extended the stewer functions that relate to the animations to get it to show. But I was hoping there was a better way to do it.

I'm sorry, but my lack of lua knowledge is showing here,

I'm not sure what you mean extended the stewer functions?

There is this


Which seemed to have the same issue (solved), but I can't figure out what was done to fix it.
"The solution was to remove the recipe & call to AddCookerRecipe from scripts/prefabs/applesauce.lua, leaving only the prefab code there, and create a new file called scripts/recipes.lua, which I then ensured loaded through my modmain.lua with a call to modimport("scripts/recipes.lua"). "

Share this post


Link to post
Share on other sites
IronHunter    355
On 8/6/2019 at 8:22 AM, MidrealmDM said:

I'm sorry, but my lack of lua knowledge is showing here,

I'm not sure what you mean extended the stewer functions?

There is this


Which seemed to have the same issue (solved), but I can't figure out what was done to fix it.
"The solution was to remove the recipe & call to AddCookerRecipe from scripts/prefabs/applesauce.lua, leaving only the prefab code there, and create a new file called scripts/recipes.lua, which I then ensured loaded through my modmain.lua with a call to modimport("scripts/recipes.lua"). "

The problem I have is that we already don't run AddCookerRecipe in the prefab, its run in modmain...my problem is even if I clone the spiced_foods.lua from the game and just change what is there I still can't get the custom crockpot food to show up on the portable spicer.

My current methods are below

Spoiler

--Modmain:
	local spicedfoods = require("rn_spicedfoods")
	for k, recipe in pairs (spicedfoods) do
		AddCookerRecipe("portablespicer", recipe)
	end
--postinitprefab
local testfoods = {}
for k,v in pairs(GLOBAL.MergeMaps(require("shipwreckedfood"), require("rubbernutsfood"))) do
	testfoods[k] = true
end
AddPrefabPostInit("portablespicer", function(inst)
	if GLOBAL.TheWorld.ismastersim then	
		local function showproduct(inst)
			local product = inst.components.stewer.product
			--print(product)
			local recipe = cooking.GetRecipe(inst.prefab, product)
			if recipe ~= nil then
				--print(recipe.basename)
				product = recipe.basename or product
				--print(product)
			end
			if testfoods[product] then
				inst.AnimState:OverrideSymbol("swap_cooked", product, product)
			end
		end
		local _continuedonefn = inst.components.stewer.oncontinuedone
		local _donecookfn = inst.components.stewer.ondonecooking
		inst.components.stewer.oncontinuedone = function(inst)_continuedonefn(inst)showproduct(inst)end
		inst.components.stewer.ondonecooking = function(inst)_donecookfn(inst)showproduct(inst)end
	end
end)

you may need to fix some globals
and I am also in the rot beta

I have scoured the workshop to try and figure out how others have done it successfully like island adventures, but I haven't been able to replicate anything that works. Beyond this somewhat hacky solution.

rn_spicedfoods.lua

rn_cookpotfood.lua

shipwreckedfood.lua

Capture.PNG

Share this post


Link to post
Share on other sites
eXiGe    62

This was a bug that was fixed on the release branch. The fix hasn't made its way to the beta branch yet.

Share this post


Link to post
Share on other sites
IronHunter    355
8 hours ago, eXiGe said:

This was a bug that was fixed on the release branch. The fix hasn't made its way to the beta branch yet.

No wonder it was driving me crazy lols, I thought it was pushed already in one of the recent patches.

Share this post


Link to post
Share on other sites
IronHunter    355

Can confirm that after the return of them joined the release version the spiced mod foods works for me. Now so my work around is no longer needed.

Share this post


Link to post
Share on other sites
MidrealmDM    102

Well.. I just checked and its still not working for me.. so i've done something wrong

@IronHunter

- What is the name of your mod? maybe I should look over the whole thing?

Share this post


Link to post
Share on other sites
MidrealmDM    102
On 8/8/2019 at 3:58 AM, IronHunter said:

The problem I have is that we already don't run AddCookerRecipe in the prefab, its run in modmain...my problem is even if I clone the spiced_foods.lua from the game and just change what is there I still can't get the custom crockpot food to show up on the portable spicer.

 

Well, I was running AddCookerRecipe from the prefabs... and apparently that made the difference.
I moved the AddCookerRecipe lines to the modmain and all the images load properly now.

Hooray!

Thank you @IronHunter for all of your patience and assistance.

Share this post


Link to post
Share on other sites