Jump to content

bad argument #1 to 'ipairs'


Recommended Posts

I have a character mod that I was developing and it was working previously, and now has suddenly stopped working - the following error.

 

scripts/mods.lua(17,1) error calling LoadPrefabFile in mod winfred (Winfred KL9):
...n/dont_starve/data/scripts/prefabs/player_common.lua:162: bad argument #1 to 'ipairs' (table expected, got function)

 

scripts/mods.lua(17,1) error calling LoadPrefabFile in mod winfred (Winfred KL9):
...n/dont_starve/data/scripts/prefabs/player_common.lua:162: bad argument #1 to 'ipairs' (table expected, got function)
LUA ERROR stack traceback:
        =[C] in function 'ipairs'
        D:/Steam/steamapps/common/dont_starve/data/scripts/prefabs/player_common.lua(162,1)
        =(tail call) ?
        D:/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua(73,1)
        =(tail call) ?
        =[C] in function 'xpcall'
        D:/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(15,1)
        D:/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(271,1) in function 'RegisterPrefabs'
        D:/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(107,1) in function 'LoadAssets'
        D:/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(1144,1) in function 'DoResetAction'
        D:/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(1159,1) in function 'complete_callback'
    ...
        =[C] in function 'GetPersistentString'
        D:/Steam/steamapps/common/dont_starve/data/scripts/saveindex.lua(89,1) in function 'Load'
        D:/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(1180,1) in function 'callback'
        D:/Steam/steamapps/common/dont_starve/data/scripts/playerprofile.lua(534,1) in function 'Set'
        D:/Steam/steamapps/common/dont_starve/data/scripts/playerprofile.lua(412,1)
        =[C] in function 'GetPersistentString'
        D:/Steam/steamapps/common/dont_starve/data/scripts/playerprofile.lua(410,1) in function 'Load'
        D:/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(1179,1) in main chunk
        =[C] in function 'require'
        D:/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua(651,1)    
scripts/mods.lua(221,1) Disabling winfred (Winfred KL9) because it had an error.    
scripts/frontend.lua(723,1) SCRIPT ERROR! Showing error screen    
scripts/mods.lua(287,1) Mod: winfred (Winfred KL9)      Registering default mod prefab    
scripts/screens/mainscreen.lua(525,1) platform_motd    table: 09551B58  

 

I dont have anything about ipairs in my mod and line 162 of player_common.lua is blank.

 

So I am not even sure where to begin.

 

Thanks for any help

 

Below is the character prefab.lua

 

local MakePlayerCharacter = require "prefabs/player_common"

local assets = {
        Asset( "ANIM", "anim/player_basic.zip" ),
        Asset( "ANIM", "anim/player_idles_shiver.zip" ),
        Asset( "ANIM", "anim/player_actions.zip" ),
        Asset( "ANIM", "anim/player_actions_axe.zip" ),
        Asset( "ANIM", "anim/player_actions_pickaxe.zip" ),
        Asset( "ANIM", "anim/player_actions_shovel.zip" ),
        Asset( "ANIM", "anim/player_actions_blowdart.zip" ),
        Asset( "ANIM", "anim/player_actions_eat.zip" ),
        Asset( "ANIM", "anim/player_actions_item.zip" ),
        Asset( "ANIM", "anim/player_actions_uniqueitem.zip" ),
        Asset( "ANIM", "anim/player_actions_bugnet.zip" ),
        Asset( "ANIM", "anim/player_actions_fishing.zip" ),
        Asset( "ANIM", "anim/player_actions_boomerang.zip" ),
        Asset( "ANIM", "anim/player_bush_hat.zip" ),
        Asset( "ANIM", "anim/player_attacks.zip" ),
        Asset( "ANIM", "anim/player_idles.zip" ),
        Asset( "ANIM", "anim/player_rebirth.zip" ),
        Asset( "ANIM", "anim/player_jump.zip" ),
        Asset( "ANIM", "anim/player_amulet_resurrect.zip" ),
        Asset( "ANIM", "anim/player_teleport.zip" ),
        Asset( "ANIM", "anim/wilson_fx.zip" ),
        Asset( "ANIM", "anim/player_one_man_band.zip" ),
        Asset( "ANIM", "anim/shadow_hands.zip" ),
        Asset( "ANIM", "anim/beard.zip" ),
        Asset( "SOUND", "sound/sfx.fsb" ),

        -- Don't forget to include your character's custom assets!
        Asset( "ANIM", "anim/winfred.zip" ),
}

local function custom_init(inst)

    STRINGS.CHARACTERS.WINFRED = require "speech_winfred"

end

local function dohaterain(inst, dt)

    local mitigates_rain = inst.components.inventory:IsWaterproof()
    
   if GetSeasonManager() and GetSeasonManager():IsRaining() then
    
        if not mitigates_rain then
            inst.components.sanity.dapperness = (-TUNING.DAPPERNESS_LARGE * GetSeasonManager():GetPrecipitationRate())
        else
            inst.components.sanity.dapperness = (-TUNING.DAPPERNESS_MED * GetSeasonManager():GetPrecipitationRate())
        end
    
    else
            inst.components.sanity.dapperness = 0
    end
end    


local fn = function(inst)

    inst:DoPeriodicTask(0.2, function() dohaterain(inst, 0.2) end)
    
    inst.components.temperature.inherentsummerinsulation = (TUNING.INSULATION_SMALL *2.5 )
    inst.components.temperature.inherentinsulation = (TUNING.INSULATION_SMALL *2.5 )
           
    inst.components.health:SetMaxHealth(150)
    inst.components.hunger:SetMax(150)
    inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 1.15)
    inst.components.sanity:SetMax(200)
    inst.components.combat.damagemultiplier = 1.0
    inst.components.combat.min_attack_period = 0.5
    inst.components.locomotor.walkspeed = (TUNING.WILSON_WALK_SPEED * 1.0)
    inst.components.locomotor.runspeed = (TUNING.WILSON_RUN_SPEED * 1.0)
    
    -- choose which sounds this character will play
    inst.soundsname = "winfred"

    -- a minimap icon must be specified
    inst.MiniMapEntity:SetIcon( "winfredmini.png" )

end    

return MakePlayerCharacter("winfred", assets, fn)

 

Link to comment
Share on other sites

I have a character mod that I was developing and it was working previously, and now has suddenly stopped working - the following error.

 

scripts/mods.lua(17,1) error calling LoadPrefabFile in mod winfred (Winfred KL9):

...n/dont_starve/data/scripts/prefabs/player_common.lua:162: bad argument #1 to 'ipairs' (table expected, got function)

 

scripts/mods.lua(17,1) error calling LoadPrefabFile in mod winfred (Winfred KL9):

...n/dont_starve/data/scripts/prefabs/player_common.lua:162: bad argument #1 to 'ipairs' (table expected, got function)

LUA ERROR stack traceback:

        =[C] in function 'ipairs'

        D:/Steam/steamapps/common/dont_starve/data/scripts/prefabs/player_common.lua(162,1)

        =(tail call) ?

        D:/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua(73,1)

        =(tail call) ?

        =[C] in function 'xpcall'

        D:/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(15,1)

        D:/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(271,1) in function 'RegisterPrefabs'

        D:/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(107,1) in function 'LoadAssets'

        D:/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(1144,1) in function 'DoResetAction'

        D:/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(1159,1) in function 'complete_callback'

    ...

        =[C] in function 'GetPersistentString'

        D:/Steam/steamapps/common/dont_starve/data/scripts/saveindex.lua(89,1) in function 'Load'

        D:/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(1180,1) in function 'callback'

        D:/Steam/steamapps/common/dont_starve/data/scripts/playerprofile.lua(534,1) in function 'Set'

        D:/Steam/steamapps/common/dont_starve/data/scripts/playerprofile.lua(412,1)

        =[C] in function 'GetPersistentString'

        D:/Steam/steamapps/common/dont_starve/data/scripts/playerprofile.lua(410,1) in function 'Load'

        D:/Steam/steamapps/common/dont_starve/data/scripts/gamelogic.lua(1179,1) in main chunk

        =[C] in function 'require'

        D:/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua(651,1)    

scripts/mods.lua(221,1) Disabling winfred (Winfred KL9) because it had an error.    

scripts/frontend.lua(723,1) SCRIPT ERROR! Showing error screen    

scripts/mods.lua(287,1) Mod: winfred (Winfred KL9)      Registering default mod prefab    

scripts/screens/mainscreen.lua(525,1) platform_motd    table: 09551B58  

 

I dont have anything about ipairs in my mod and line 162 of player_common.lua is blank.

 

So I am not even sure where to begin.

 

Thanks for any help

 

It seems that you are passing a function as a table. To be specific, your assets table (which in your case isn't a table) is the issue, I believe.

Link to comment
Share on other sites

It seems that you are passing a function as a table. To be specific, your assets table (which in your case isn't a table) is the issue, I believe.

 

Well, like I said, it was working previously and I'm not sure what part/file needs to be fixed. I didnt make any changes, but I hadn't tried to run it in the past month or two, so it has something to do with the lastest updates to Don't Starve.

 

I've attached the player prefab.lua (see original post) - any ideas where the problem lies?

 

And thanks again for the assist

Link to comment
Share on other sites

It seems that you are passing a function as a table. To be specific, your assets table (which in your case isn't a table) is the issue, I believe.

Precisely.

There should be a 'nil' before the assets table in the MakePlayerCharacter call. And player_common.lua:162 is not blank, you're probably just reading the vanilla file instead of the RoG one.

Link to comment
Share on other sites

Precisely.

And player_common.lua:162 is not blank, you're probably just reading the vanilla file instead of the RoG one.

 

You are correct...

The log referenced D:/Steam/steamapps/common/dont_starve/data/scripts/prefabs/player_common.lua(162,1)

so that is precisely where I looked. But in the DLC folder I found a different one and it does contain

 

 if customprefabs then

        for k,v in ipairs(customprefabs) do

            table.insert(prefabs, v)

        end

    end

 

Precisely.

There should be a 'nil' before the assets table in the MakePlayerCharacter call.

 

I assume nil isn't just a blank line -

Link to comment
Share on other sites

No, nil is nil :razz:. You should replace the last line in your prefab file with

return MakePlayerCharacter("winfred", nil, assets, fn)

 

lol - ok - :kiwi:

I had just figured out something similar after reading line 162 and seeing that the error was rooted in prefabs

 

I added the line

local prefabs = {}

and then

local return MakePlayerCharacter("winfred", prefab, assets, fn)

And that seemed to work as well.

 

Thanks much to both of you!

Link to comment
Share on other sites

lol - ok - :kiwi:

I had just figured out something similar after reading line 162 and seeing that the error was rooted in prefabs

 

I added the line

local prefabs = {}

and then

local return MakePlayerCharacter("winfred", prefab, assets, fn)

And that seemed to work as well.

 

Thanks much to both of you!

Yeah, that does exactly the same thing. If you pass nil as the prefab table, it gets replaced with an empty table.

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