Icywaffle Posted December 27, 2014 Share Posted December 27, 2014 local function master_postinit(inst) inst.soundsname = "willow" inst.entity:AddMiniMapEntity() inst.MiniMapEntity:SetIcon( "musha.tex" ) inst.level = 0 inst.components.eater:SetOnEatFn(expeat)inst:ListenForEvent("levelup", levelexp) inst.strength = "normal" inst.components.health:SetMaxHealth(70) inst.components.hunger:SetMax(200)This is the code in question. I cant understand the concept around splitting the original. local fn = function(init) into the master_postinit(inst) and the common_postinit(inst).If I try to remove that inst.components.eater:SetOnEatFn(expeat)it then gives me the error of attempting to index field 'health', right below the first one. and this is my return line for the prefab.return MakePlayerCharacter("musha", prefabs, assets, master_postinit, start_inv)Error given:[string "../mods/workshop-363255966/scripts/prefabs/..."]:2355: attempt to index field 'eater' (a nil value)LUA ERROR stack traceback:../mods/workshop-363255966/scripts/prefabs/musha.lua:2355 in (upvalue) common_postinit (Lua) <2349-2422> inst = 110478 - (valid:true)scripts/prefabs/player_common.lua:1047 in (field) fn (Lua) <980-1233> inst = 110478 - (valid:true)scripts/mainfunctions.lua:147 in () ? (Lua) <136-167> name = musha prefab = Prefab musha - Also, I feel as if I don't completely understand the AddSimPostInit replacement, or its actual function/use for the MODMAIN.lua.AddPrefabPostInit(function(inst) if inst.prefab == "musha" then mushaPostInit(inst) endI replaced the AddSimPostInit(function(inst) with the one on the first line here. My purpose is to port a DS mod into a DST mod, and only for personal use, unless the creator gives permission for me to share. Also, I want to understand how the mods work in a little more depth. Link to comment Share on other sites More sharing options...
rezecib Posted December 27, 2014 Share Posted December 27, 2014 return MakePlayerCharacter("musha", prefabs, assets, master_postinit, start_inv) This should be this instead:return MakePlayerCharacter("musha", prefabs, assets, common_postinit, master_postinit, start_inv)Currently it's loading your master_postinit as the common_postinit, which is what runs on clients (also the server), and the eater component only exists on the host, so you need it to be running as the master_postinit. As I understand it, AddSimPostInit is for code that you want to run without being attached to any particular entity. From looking at other mods, it seems to be incredibly overused-- most of the time you would be better off with an AddPrefabPostInit, AddClassPostConstruct, etc. In the case you showed, though, that AddPrefabPostInit won't work. The first argument of AddPrefabPostInit is the prefab name you want it to run with, so you should do this instead:AddPrefabPostInit("musha", mushaPostInit)The way you have it written is in the form of AddPrefabPostInitAny, which runs on all prefabs. This is generally nice to avoid, since that's extra overhead any time anything in the game is spawned, but is sometimes useful because you can key it onto a tag or something instead of just the prefab name. Link to comment Share on other sites More sharing options...
Icywaffle Posted December 27, 2014 Author Share Posted December 27, 2014 [string "../mods/workshop-363255966/scripts/prefabs/..."]:2435: variable 'common_postinit' is not declaredLUA ERROR stack traceback: =[C] in function 'error' scripts/strict.lua(23,1) ../mods/workshop-363255966/scripts/prefabs/musha.lua(2435,1) in function 'fn' scripts/mainfunctions.lua(94,1) =(tail call) ? =[C] in function 'xpcall' scripts/mods.lua(105,1) scripts/mods.lua(396,1) in function 'RegisterPrefabs' scripts/gamelogic.lua(158,1) in function 'LoadAssets' scripts/gamelogic.lua(1097,1) in function 'DoResetAction' scripts/gamelogic.lua(1113,1) in function 'complete_callback' ... =[C] in function 'GetPersistentString' scripts/saveindex.lua(90,1) in function 'Load' scripts/gamelogic.lua(1135,1) in function 'callback' scripts/playerprofile.lua(645,1) in function 'Set' scripts/playerprofile.lua(528,1) =[C] in function 'GetPersistentString' scripts/playerprofile.lua(526,1) in function 'Load' scripts/gamelogic.lua(1134,1) in main chunk =[C] in function 'require' scripts/mainfunctions.lua(677,1) After adding that common_postinit into the return line, this error appears. I'm partially confused on how to split the fn. Link to comment Share on other sites More sharing options...
rezecib Posted December 28, 2014 Share Posted December 28, 2014 @Icywaffle, Oh, oops. Since you don't have a common_postinit at all, you can leave that as nil. For some reason I thought it would just treat it as nil there, but I guess that only goes for grabbing things off of tables. So:return MakePlayerCharacter("musha", prefabs, assets, nil, master_postinit, start_inv) Link to comment Share on other sites More sharing options...
Icywaffle Posted December 28, 2014 Author Share Posted December 28, 2014 AddPrefabPostInit("musha", mushaPostInit) if inst.prefab == "musha" then mushaPostInit(inst) endend)Now, this is the last problem I'm having. [string "../mods/workshop-363255966/modmain.lua"]:358: '<eof>' expected near 'end' Since I replaced that above PrefabPostInit, is there something I'm forgetting to do? Link to comment Share on other sites More sharing options...
Icywaffle Posted December 28, 2014 Author Share Posted December 28, 2014 I'm going to guess that if inst.prefab == "musha" thenmushaPostInit(inst) end Is not even needed after replacing it with the given code, and I'm just retarded. Link to comment Share on other sites More sharing options...
rezecib Posted December 28, 2014 Share Posted December 28, 2014 Is not even needed after replacing it with the given code That's correct. You don't need the other "end)", either. 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