HomShaBom Posted November 30, 2016 Share Posted November 30, 2016 Accidentally posted this in the DS forum, meant to post it here in the DST forum... I want to add a haunting effect to "smallmeat" so in my modmain.lua I have: AddPrefabPostInit("smallmeat", function(inst) --here I want to call AddMonsterMeatChange(inst, "someotherprefab") that exists in \data\scripts\prefabs\meats.lua end) Is this possible, or will I have to just duplicate this method inside of my modmain.lua? Also, related, what if I need to call a method on a new custom prefab and also on an existing prefab? Am I required to define that function twice as well (once in the new prefab's .lua file where I am creating the prefab, and once in the modmain.lua where I call AddPrefabPostInit)? Link to comment Share on other sites More sharing options...
DarkXero Posted November 30, 2016 Share Posted November 30, 2016 AddMonsterMeatChange is a local variable to the meats.lua file. You can't call it from modmain, or from anywhere else. You need to copy paste the method. If you put in your custom prefab file the function MyGlobalFunctionInPrefab(inst, prefab) end without the "local", then the function will be global. And you can call globals from modmain like AddPrefabPostInit("smallmeat", function(inst) GLOBAL.MyGlobalFunctionInPrefab(inst) end) You can also make global functions from modmain, like GLOBAL.ThisWillBeGlobal = function() end You can even create a new lua file (myfunctions.lua) that looks like local func1 = function() end local func2 = function() end return { dothis = func1, dothat = func2, } and then you can do local myfuncs = require("myfunctions") -- returns the table with the functions myfuncs.dothis() -- calls func1 myfuncs.dothat() -- calls func2 wherever you want. 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