Custom events to load Lua scripts

SamBC

Emperor
Joined
Feb 2, 2010
Messages
1,052
Location
Lancaster
I'm sure this has been covered, but I've tried searching the forum and no luck...

I recall there being a way to create a new mod event (the kind that actions in the mod tie to), that allows one to load Lua files - so a modcomp would contain code to fire off the event, and then those other Lua files would get loaded. I think this may even be used natively for some of the UI stuff. Can anyone point me at it, or explain it?

I wish there was a list of all of the native events for mod loading, and all valid actions for them...
 
You can add them to the content tab, not the actions tab. At the bottom of InGame.lua you'll find this:

Code:
g_uiAddins = {};
for addin in Modding.GetActivatedModEntryPoints("InGameUIAddin") do
	local addinFile = Modding.GetEvaluatedFilePath(addin.ModID, addin.Version, addin.File);
	local addinPath = addinFile.EvaluatedPath;
	
	-- Get the absolute path and filename without extension.
	local extension = Path.GetExtension(addinPath);
	local path = string.sub(addinPath, 1, #addinPath - #extension);
	
	table.insert(g_uiAddins, ContextPtr:LoadNewContext(path));
end

Just replace "InGameUIAddin" with your own content type and copy the code, it's quite easy.
 
So you have to replace-add one lua file, basically, and then you can use that to define ways to add others. Has no-one done a proposed community standard modcomp for this yet?

It would be nicer if it weren't necessary to replace any lua files, but there you go.
 
So you have to replace-add one lua file, basically, and then you can use that to define ways to add others. Has no-one done a proposed community standard modcomp for this yet?

It would be nicer if it weren't necessary to replace any lua files, but there you go.

You can have lua files loaded from InGame by setting content type to InGameUIAddin so you don't necessarily have to replace anything unless you want to change a UI screen
 
You can have lua files loaded from InGame by setting content type to InGameUIAddin so you don't necessarily have to replace anything unless you want to change a UI screen
The thing I wonder about with that is whether it works for Lua that's to change (or rather add) behaviour, rather than UI alteration. I suspect this will be particularly relevant once we start trying to use the new GameEvents interface (as soon as they see fit to actually let us know how).
 
The thing I wonder about with that is whether it works for Lua that's to change (or rather add) behaviour, rather than UI alteration. I suspect this will be particularly relevant once we start trying to use the new GameEvents interface (as soon as they see fit to actually let us know how).

The game doesn't clearly distinguish between UI and content scripts, any context you load will be able to do both.
 
Okay, I've come up with one more question from this - at what point in the game-starting sequence are InGameUIAddin contexts loaded? I presume that it's after map gen, starting location selection, etc, but if it's not I'd love to know.
 
Okay, I've come up with one more question from this - at what point in the game-starting sequence are InGameUIAddin contexts loaded? I presume that it's after map gen, starting location selection, etc, but if it's not I'd love to know.

They're executed when InGame.lua is executed, which is after the map set-up but before you click on Begin Your Journey
 
Back
Top Bottom