blindcoder Posted August 26, 2015 Share Posted August 26, 2015 (edited) I'm currently working on a mod that introduces an Event that other mods can then use:LuaEventManager.AddEvent("MyModEvent");Now I can use that in another mod:Events.MyModEvent.Add(OtherMod.CallThisFunction);The only problem is: if MyModEvent doesn't exist because the Mod isn't loaded, the above will cause a Null Pointer Exception (calling method Add of nil).But even if I check isModEnabled("MyMod") won't solve this, because there's no guarenteed mod loading order.And IIRC require won't work properly inside thisif isModEnabled("MyMod") then require("MyModEventSetup.lua");endAny ideas? Edited August 26, 2015 by blindcoder Link to comment Share on other sites More sharing options...
blindcoder Posted August 26, 2015 Author Share Posted August 26, 2015 Okay, never mind, if isModEnabled then require works fine after all. I misremembered Link to comment Share on other sites More sharing options...
Aricane Posted August 26, 2015 Share Posted August 26, 2015 So you're certain all mods were loaded at that point? Link to comment Share on other sites More sharing options...
blindcoder Posted August 26, 2015 Author Share Posted August 26, 2015 So you're certain all mods were loaded at that point? If you require the file, you can be, yes.I'm doing this now successfully:if getActivatedMods():contains("MyMod") then require("MyMod.lua"); Events.MyModEvent.Add(ThisMod.CallFuncion);endMyMod.lua sets up the Event "MyModEvent" which I can then hook into. 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