Chewtoy Posted July 23, 2015 Share Posted July 23, 2015 function SimPostInit(player) GLOBAL.LoadScript("commands.lua") AddTestToolController(player) end function AddTestToolController(player) player:AddComponent("testtoolcontroller") end AddSimPostInit(SimPostInit) [00:00:24]: [string "../mods/NEKIO/modmain.lua"]:145: attempt to index local 'player' (a nil value) LUA ERROR stack traceback: ../mods/NEKIO/modmain.lua(145,1) in function 'AddTestToolController' ../mods/NEKIO/modmain.lua(141,1) =(tail call) ? =[C] in function 'xpcall' scripts/mods.lua(144,1) scripts/mods.lua(620,1) in function 'SimPostInit' scripts/gamelogic.lua(654,1) in function 'DoInitGame' scripts/gamelogic.lua(771,1) in function 'cb' scripts/saveindex.lua(120,1) =[C] in function 'GetPersistentString' scripts/saveindex.lua(102,1) in function 'GetSaveDataFile' ... =[C] in function 'GetPersistentString' scripts/saveindex.lua(68,1) in function 'Load' scripts/gamelogic.lua(955,1) in function 'callback' scripts/playerprofile.lua(564,1) in function 'Set' scripts/playerprofile.lua(447,1) =[C] in function 'GetPersistentString' scripts/playerprofile.lua(445,1) in function 'Load' scripts/gamelogic.lua(954,1) in main chunk =[C] in function 'require' scripts/mainfunctions.lua(691,1) Link to comment https://forums.kleientertainment.com/forums/topic/56426-why-is-this-not-working-simpostinit/ Share on other sites More sharing options...
Kzisor Posted July 23, 2015 Share Posted July 23, 2015 @Chewtoy, what you're wanting to accomplish should be done in AddPlayerPostInit. So for your example it would be:AddPlayerPostInit( function( player ) player:AddComponent("testtoolcontroller")end) Link to comment https://forums.kleientertainment.com/forums/topic/56426-why-is-this-not-working-simpostinit/#findComment-656769 Share on other sites More sharing options...
DarkXero Posted July 23, 2015 Share Posted July 23, 2015 AddSimPostInit adds a function to a table.Then, when the world starts, they all get executed like:for k, v in pairs(simpostinits) do v(wilson)endThe thing is, that wilson is indeed the result of GetPlayer() in Don't Starve, the player playing. In DST, however, that wilson is nil. So like @Kzisor, says, you want to use AddPlayerPostInit.AddPlayerPostInit(function(player) player:DoTaskInTime(0, function() if player == GLOBAL.ThePlayer then player:AddComponent("testtoolcontroller") end end) end) Link to comment https://forums.kleientertainment.com/forums/topic/56426-why-is-this-not-working-simpostinit/#findComment-656777 Share on other sites More sharing options...
Chewtoy Posted July 23, 2015 Author Share Posted July 23, 2015 I see thanks for the reply Link to comment https://forums.kleientertainment.com/forums/topic/56426-why-is-this-not-working-simpostinit/#findComment-656784 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