Jump to content

How to optionally hook into another mods event?


blindcoder

Recommended Posts

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 this

if isModEnabled("MyMod") then  require("MyModEventSetup.lua");end

Any ideas?

Edited by blindcoder
Link to comment
Share on other sites

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);end

MyMod.lua sets up the Event "MyModEvent" which I can then hook into.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...