So far I have found 2 ways of overriding a function, but I'm in a situation where I'm not sure which applies.
1. The function is in a lua file and the lua file is included from base.xml (or, really any xml file) -
<script name="CharacterManager" file="scripts/manager_character.lua" />
If that's the case, then I can use the name: CharacterManager.whateverFunctionName = new function
2. The function is part of a script section that is included directly as part of a xml file and only referenced in there
For this I can use merge to override the entire script section instead of just the one function -
<root>
<template name="pc_traitdiebase">
<traitdiebase merge="replace">
<script>
function onInit()
But now I've hit a new situation.
3. The function is in a lua file, but that lua file is not referenced as part of the base.xml. Instead, it is only references once under a windowclass in an xml -
<windowclass name="npc_skillentry">
<sizelimits>
<minimum height="42" />
</sizelimits>
<script file="campaign/scripts/npc_skill.lua"/>
It is never assigned a name for external referencing, so I can't use method 1. But it also doesn't have local code, so method 2 doesn't exactly match either.
I'm thinking I can make a copy of the lua with an altered name. Then use method 2 to merge the new name as a replacement -
<script file="campaign/scripts/npc_skill_replace.lua"/>
Which would mean the new lua file would need to contain all of the functions of the old file even if I am only altering one of them.
Is there a better method of doing this?