MrDoge124 Posted February 26, 2017 Share Posted February 26, 2017 I'm trying to make a backpack for my custom character but I got this error. [string "../mods/Green's backpack/modmain.lua"]:25: attempt to index local 'player' (a nil value) LUA ERROR stack traceback: ../mods/Green's backpack/modmain.lua(25,1) =(tail call) ? =[C] in function 'xpcall' scripts/mods.lua(131,1) scripts/mods.lua(709,1) in function 'SimPostInit' scripts/gamelogic.lua(688,1) in function 'DoInitGame' scripts/gamelogic.lua(789,1) in function 'cb' scripts/saveindex.lua(285,1) =[C] in function 'GetPersistentString' scripts/saveindex.lua(267,1) in function 'GetSaveDataFile' scripts/saveindex.lua(293,1) in function 'GetSaveData' Anyone know whats going wrong? modmain.lua Link to comment Share on other sites More sharing options...
Cunning fox Posted February 28, 2017 Share Posted February 28, 2017 You can try this: function SimInit(player) if player ~= nil then print("spawning item") local prefab = SpawnPrefab("green_backpack") player.components.inventory:GiveItem(prefab) end end But I don't know will it work or not. 1 Link to comment Share on other sites More sharing options...
MrDoge124 Posted February 28, 2017 Author Share Posted February 28, 2017 (edited) Where should I put this code? I'm not really sure. in the modmain.lua file right? or green_backpack? Edited February 28, 2017 by MrDoge124 Link to comment Share on other sites More sharing options...
MrDoge124 Posted February 28, 2017 Author Share Posted February 28, 2017 I tried the code and figured out that I had to put it in modmain.lua and it got to the character select screen which is great! But i got a new error when playing as the character that the back pack is meant for. [string "scripts/components/inventory.lua"]:634: attempt to index local 'inst' (a nil value) LUA ERROR stack traceback: scripts/components/inventory.lua:634 in (method) GiveItem (Lua) <633-766> scripts/prefabs/player_common.lua:1892 in (method) OnNewSpawn (Lua) <1888-1900> scripts/networking.lua:250 in () ? (Lua) <238-256> =[C]:-1 in (method) SendSpawnRequestToServer (C) <-1--1> scripts/mainfunctions.lua:1272 in (local) cb (Lua) <1270-1273> scripts/frontend.lua:531 in (method) DoFadingUpdate (Lua) <495-535> scripts/frontend.lua:583 in (method) Update (Lua) <543-695> scripts/update.lua:92 in () ? (Lua) <33-129> I think it's something to do with the backpack trying to be in the inventory but it normally goes straight on the torso slot. I not really sure. Link to comment Share on other sites More sharing options...
RedHairedHero Posted March 2, 2017 Share Posted March 2, 2017 player = GLOBAL.ThePlayer Right now your code uses player, but player on it's own doesn't exist. Just put in the code above before you call your SimInit function and it should work. Link to comment Share on other sites More sharing options...
Amalleus Posted March 2, 2017 Share Posted March 2, 2017 (edited) Could you also drop us your green_backpack.lua? GiveItem doesn't see the item which you gives to it as argument. probably SpawnPrefab doesn't summon your green_backpack Edited March 2, 2017 by Amalleus Link to comment Share on other sites More sharing options...
Amalleus Posted March 2, 2017 Share Posted March 2, 2017 8 hours ago, RedHairedHero said: player = GLOBAL.ThePlayer Right now your code uses player, but player on it's own doesn't exist. Just put in the code above before you call your SimInit function and it should work. This will refer to host. And AddSimPostInit initializes on current player itself Link to comment Share on other sites More sharing options...
RedHairedHero Posted March 2, 2017 Share Posted March 2, 2017 (edited) This post might give you a better idea on what to do and how to use AddSimPostInit like @Amalleus had mentioned above. Edited March 2, 2017 by RedHairedHero Link to comment Share on other sites More sharing options...
MrDoge124 Posted March 10, 2017 Author Share Posted March 10, 2017 On 3/2/2017 at 9:02 AM, Amalleus said: Could you also drop us your green_backpack.lua? Do you mean give the file? if so here it is green_backpack.lua Link to comment Share on other sites More sharing options...
MrDoge124 Posted March 10, 2017 Author Share Posted March 10, 2017 I put player "= GLOBAL.ThePlayer" in the scripts... [string "../mods/Green's backpack/scripts/prefabs/gr..."]:112: variable 'GLOBAL' is not declared LUA ERROR stack traceback: =[C] in function 'error' scripts/strict.lua(23,1) ../mods/Green's backpack/scripts/prefabs/green_backpack.lua(112,1) in function 'fn' scripts/mainfunctions.lua(93,1) =(tail call) ? It didn't work. I'm not sure whats going on with this one... Link to comment Share on other sites More sharing options...
RedHairedHero Posted March 28, 2017 Share Posted March 28, 2017 (edited) player = GLOBAL.ThePlayer should be in the modmain, not in the green_backpack.lua. Let me know if you get any other errors. If you want to provide the entire folder I can test it on my own and try to fix it if needed. Edited March 28, 2017 by RedHairedHero Link to comment Share on other sites More sharing options...
MrDoge124 Posted March 31, 2017 Author Share Posted March 31, 2017 I'm going to upload the files for you to have a look at as I'm less experienced in coding. green_backpack.zip Link to comment 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