Jump to content

Recommended Posts

I've been trying to makea custom crock pot.
It's all working until I press the cook button.
The error is in this part of the code, near the RPC.DoWidgetButtonAction part.

413: attempt to index global 'RPC' (a nil value)

This is the code

function params.m_portablecookpot.widget.buttoninfo.fn(inst, doer)
    if inst.components.container ~= nil then
        BufferedAction(doer, inst, ACTIONS.COOK):Do()
    elseif inst.replica.container ~= nil and not inst.replica.container:IsBusy() then
        SendModRPCToServer(RPC.DoWidgetButtonAction, ACTIONS.COOK.code, inst, ACTIONS.COOK.mod_name)
    end
end

Thanks for taking the time to read this.

Link to comment
https://forums.kleientertainment.com/forums/topic/133726-custom-crockpot-help/
Share on other sites

function params.m_portablecookpot.widget.buttoninfo.fn(inst, doer)
    if inst.components.container ~= nil then
        BufferedAction(doer, inst, ACTIONS.COOK):Do()
    elseif inst.replica.container ~= nil and not inst.replica.container:IsBusy() then
        SendModRPCToServer(GLOBAL.RPC.DoWidgetButtonAction, ACTIONS.COOK.code, inst, ACTIONS.COOK.mod_name)
    end
end

As the error already tells you, RPC is not defined. As you are in the modmain, you need to add a GLOBAL before it to use the correct environement.

If you haven't declared 

local ACTIONS = GLOBAL.ACTIONS

beforehand, you will also need to add a GLOBAL before ACTIONS :)

  • Like 1

I tried adding GLOBAL. onto RPC and it got another error.

[00:02:33]: [string "scripts/modutil.lua"]:632: attempt to index local 'id_table' (a number value)
LUA ERROR stack traceback:
    ../mods/Meowzers/modmain.lua:413 in (field) fn (Lua) <409-415>
    scripts/widgets/containerwidget.lua:70 in (field) onclick (Lua) <56-71>
    scripts/widgets/imagebutton.lua:206 in (method) OnControl (Lua) <166-213>
    scripts/widgets/widget.lua:112 in (method) OnControl (Lua) <106-120>
    scripts/widgets/widget.lua:112 in (method) OnControl (Lua) <106-120>
    scripts/widgets/widget.lua:112 in (method) OnControl (Lua) <106-120>
    scripts/widgets/widget.lua:112 in (method) OnControl (Lua) <106-120>
    scripts/widgets/widget.lua:112 in (method) OnControl (Lua) <106-120>
    scripts/widgets/widget.lua:112 in (field) OnControl (Lua) <106-120>
    scripts/screens/playerhud.lua:883 in () ? (Lua) <882-990>
    =(tail call):-1 in ()  (tail) <-1--1>
    scripts/frontend.lua:371 in (method) OnControl (Lua) <357-413>
    scripts/input.lua:165 in (method) OnControl (Lua) <162-169>
    scripts/input.lua:384 in () ? (Lua) <383-385>

Not quite sure what's going on.

How would I declare a RPC?

Edited by MrDoge124
Added a question

 It started cooking but for some reason crashed
This is the error it put out.

Spoiler

[00:00:56]: [string "scripts/components/stewer.lua"]:148: attempt to index a nil value
LUA ERROR stack traceback:
scripts/actions.lua:1293 in (field) fn (Lua) <1257-1353>
   act = Cook 106189 - m_portablecookpot (valid:true)
   container = table: 0000000031C62EC0
scripts/bufferedaction.lua:25 in (method) Do (Lua) <21-35>
   self (valid:true) =
      action = table: 0000000010976FE0
      doer = 118887 - meowzers (valid:true)
      onfail = table: 0000000029DD8620
      doerownsobject = false
      rotation = 0
      onsuccess = table: 0000000029DD8440
      options = table: 0000000029DD9FC0
      target = 106189 - m_portablecookpot (valid:true)
scripts/containers.lua:236 in (field) fn (Lua) <234-240>
   inst = 106189 - m_portablecookpot (valid:true)
   doer = 118887 - meowzers (valid:true)
scripts/networkclientrpc.lua:411 in () ? (Lua) <399-415>
   player = 118887 - meowzers (valid:true)
   action = 47
   target = 106189 - m_portablecookpot (valid:true)
   mod_name = nil
   playercontroller = table: 0000000018515C30
   container = table: 0000000031C62EC0
   widget = table: 0000000010529510
   buttoninfo = table: 0000000010528D90
=[C]:-1 in (method) CallRPC (C) <-1--1>
scripts/networkclientrpc.lua:1070 in (global) HandleRPCQueue (Lua) <1061-1106>
   i = 1
   fn = function - scripts/networkclientrpc.lua:399
   sender = 118887 - meowzers (valid:true)
   data = table: 0000000029DD60A0
   tick = true
scripts/update.lua:46 in () ? (Lua) <33-140>
   dt = 0.016661699861288

[00:00:56]: [string "scripts/components/stewer.lua"]:148: attempt to index a nil value
LUA ERROR stack traceback:
    scripts/actions.lua:1293 in (field) fn (Lua) <1257-1353>
    scripts/bufferedaction.lua:25 in (method) Do (Lua) <21-35>
    scripts/containers.lua:236 in (field) fn (Lua) <234-240>
    scripts/networkclientrpc.lua:411 in () ? (Lua) <399-415>
    =[C]:-1 in (method) CallRPC (C) <-1--1>
    scripts/networkclientrpc.lua:1070 in (global) HandleRPCQueue (Lua) <1061-1106>
    scripts/update.lua:46 in () ? (Lua) <33-140>

 

It seems to be having issues in the stewer.lua component.

You probably didn't add the recipes to your crock pot, that's why it's looking at an empty list and can't return anything.

I think you can do it with:

local foods = require("preparedfoods")
for k,recipe in pairs (foods) do
	AddCookerRecipe("your_crock_pot_prefab", recipe) 
end

 

  • Like 1

What does the prefab file of your cookpot look like?

Did you add a code snippet like this one?

local function SetProductSymbol(inst, product, overridebuild)
    local recipe = cooking.GetRecipe(inst.prefab, product)
    local potlevel = recipe ~= nil and recipe.potlevel or nil
    local build = (recipe ~= nil and recipe.overridebuild) or overridebuild or "cook_pot_food"
    local overridesymbol = (recipe ~= nil and recipe.overridesymbolname) or product

    if potlevel == "high" then
        inst.AnimState:Show("swap_high")
        inst.AnimState:Hide("swap_mid")
        inst.AnimState:Hide("swap_low")
    elseif potlevel == "low" then
        inst.AnimState:Hide("swap_high")
        inst.AnimState:Hide("swap_mid")
        inst.AnimState:Show("swap_low")
    else
        inst.AnimState:Hide("swap_high")
        inst.AnimState:Show("swap_mid")
        inst.AnimState:Hide("swap_low")
    end

    inst.AnimState:OverrideSymbol("swap_cooked", build, overridesymbol)
end

local function spoilfn(inst)
    if not inst:HasTag("burnt") then
        inst.components.stewer.product = inst.components.stewer.spoiledproduct
        SetProductSymbol(inst, inst.components.stewer.product)
    end
end

local function ShowProduct(inst)
    if not inst:HasTag("burnt") then
        local product = inst.components.stewer.product
        SetProductSymbol(inst, product, IsModCookingProduct(inst.prefab, product) and product or nil)
    end
end

This is from cookpot.lua, I think this one makes the cookpot show the product.

  • Like 1

Yes I do have this code in the file, I'm using the portable crock pot as a base. The code was already there and I haven't done anything to it.
This is what mine looks like right now.

Spoiler

local function SetProductSymbol(inst, product, overridebuild)
    local recipe = cooking.GetRecipe(inst.prefab, product)
    local potlevel = recipe ~= nil and recipe.potlevel or nil
    local build = (recipe ~= nil and recipe.overridebuild) or overridebuild or "cook_pot_food"
    local overridesymbol = (recipe ~= nil and recipe.overridesymbolname) or product

    if potlevel == "high" then
        inst.AnimState:Show("swap_high")
        inst.AnimState:Hide("swap_mid")
        inst.AnimState:Hide("swap_low")
    elseif potlevel == "low" then
        inst.AnimState:Hide("swap_high")
        inst.AnimState:Hide("swap_mid")
        inst.AnimState:Show("swap_low")
    else
        inst.AnimState:Hide("swap_high")
        inst.AnimState:Show("swap_mid")
        inst.AnimState:Hide("swap_low")
    end

    inst.AnimState:OverrideSymbol("swap_cooked", build, overridesymbol)
end

local function spoilfn(inst)
    if not inst:HasTag("burnt") then
        inst.components.stewer.product = inst.components.stewer.spoiledproduct
        SetProductSymbol(inst, inst.components.stewer.product)
    end
end

local function ShowProduct(inst)
    if not inst:HasTag("burnt") then
        local product = inst.components.stewer.product
        SetProductSymbol(inst, product, IsModCookingProduct(inst.prefab, product) and product or nil)
    end
end

 

Thanks for you help so far!

You're welcome!

When you cook a food in the cookpot, have a look at what the client log or the server log tells you. It should probably show something.

Try to compare your mod with other mods that add custom cookpots, for example the warly mod from before warly was added to don't starve together.

  • Like 1

Try changing this:

local function ShowProduct(inst)
    if not inst:HasTag("burnt") then
        local product = inst.components.stewer.product
        SetProductSymbol(inst, product, IsModCookingProduct(inst.prefab, product) and product or nil)
    end
end

to this:

local function ShowProduct(inst)
    if not inst:HasTag("burnt") then
        local product = inst.components.stewer.product
        SetProductSymbol(inst, product)
    end
end

It seems like it sets the build as the product name instead of cook_pot_food, so this should make it use cook_pot_food.

  • Like 2

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