Jump to content

Error : attempt to index global 'inst'


Recommended Posts

Hello,

i want to create a mod to ass the masked pig bandit in shipwrecked (when towns are presents).

It's my first mod :/

Error in client log file :

 

...common/dont_starve/data/../mods/anchocho/modmain.lua:79: attempt to index global 'inst' (a nil value)
LUA ERROR stack traceback:
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/../mods/anchocho/modmain.lua(79,1) in main chunk
        =[C] in function 'xpcall'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/util.lua(552,1) in function 'RunInEnvironment'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(217,1) in function 'InitializeModMain'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mods.lua(198,1) in function 'LoadMods'
        scripts/main.lua(273,1) in function 'ModSafeStartup'
        scripts/main.lua(320,1)
        =[C] in function 'SetPersistentString'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua(26,1) in function 'SavePersistentString'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(68,1)
        =[C] in function 'GetPersistentString'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(55,1) in function 'BeginStartupSequence'
        scripts/main.lua(319,1) in function 'callback'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(338,1)
        =[C] in function 'GetPersistentString'
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/modindex.lua(318,1) in function 'Load'
        scripts/main.lua(318,1) in main chunk
	
[00:00:38]: scripts/mods.lua(206,1) Mod: workshop-712470670 ( [DS]Aerial view)	Loading modworldgenmain.lua	
[00:00:38]: scripts/mods.lua(214,1) Mod: workshop-712470670 ( [DS]Aerial view)	  Mod had no modworldgenmain.lua. Skipping.	
[00:00:38]: scripts/mods.lua(206,1) Mod: workshop-712470670 ( [DS]Aerial view)	Loading modmain.lua	

 

i suppose it's this line who create the error in modmain.lua :

inst:AddComponent("banditmanager")

( my mod is attached.)

thanks

 

 

 

anchocho.zip

Link to comment
Share on other sites

You can't just call a function on something that doesn't exist. inst is nowhere in your code here, except in your commented lines above it where you tried to spawn the world for some reason.

Try this:

GLOBAL.GetWorld():AddComponent("banditmanager")

That should work. I haven't looked at the actual banditmanager script, though.

Link to comment
Share on other sites

Thanks Ultroman for your help.

I have used

Quote

GLOBAL.GetWorld():AddComponent("banditmanager")

--> and the log file say :

Quote

...common/dont_starve/data/../mods/anchocho/modmain.lua:103: attempt to index a nil value
LUA ERROR stack traceback:
        C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/../mods/anchocho/modmain.lua(103,1) in main chunk
        =[C] in function 'xpcall'

 

And when i use :

Quote

local inst = GLOBAL.GetWorld()
AddComponentPostInit("world", function(inst)
  inst:AddComponent("banditmanager")
end)

--> the game crash only if i use the command line : c_spawn("pigbandit")

Log :

Quote

[00:01:24]: .../data/../mods/anchocho/scripts/prefabs/pigbandit.lua:216: attempt to index field 'banditmanager' (a nil value)
LUA ERROR stack traceback:
C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/../mods/anchocho/scripts/prefabs/pigbandit.lua:216 in (field) fn (Lua) <214-218>

Have you an idea ?

 

 

anchocho.zip

Link to comment
Share on other sites

World isn't a component, it's a prefab. AddComponentPostInit is for altering components. Try AddPrefabPostInit instead. And you don't need the preceding line:

local inst = GLOBAL.GetWorld()

I don't understand why GLOBAL.GetWorld() is nil in your modmain, though.

Link to comment
Share on other sites

Thanks a lot for your help :)

i have used AddPrefabPostInit like this :

Quote

AddPrefabPostInit("world", function(inst)
  inst:AddComponent("banditmanager")
end)

But i obtain the same message when the game crash :

Quote

[00:01:27]: .../data/../mods/anchocho/scripts/prefabs/pigbandit.lua:216: attempt to index field 'banditmanager' (a nil value)
LUA ERROR stack traceback:
C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/../mods/anchocho/scripts/prefabs/pigbandit.lua:216 in (field) fn (Lua) <214-218>

I hope Klei will add the masked pig in shipwrecked and RoG in the futur...

Link to comment
Share on other sites

Well, now I spent a stupid amount of time looking at this, in order to successfully procrastinate from the much more important and pertinent things I have to do, and I have to say that it would (probably?) be a mountain of work to get the bandit into Shipwrecked. After adding the bandit hat properly and actually getting the bandit to spawn in the game, it crashed because it requires changes to the locomotor component, and probably has a bunch of other functionality from Hamlet that it needs in order to...live. So I dropped it.

Porting mods is probably a bit too tall an order for your first mod.

Link to comment
Share on other sites

Hello Ultroman,

Sorry for the "stupid amount of time"... I did not know it was a big work for this little bandit. And probably it's better for me to abandon the bandit for my first mod, yes.

Thanks thanks a lot for all your help :)

 

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