Facjad
July 16th, 2025, 15:05
Hello,
I wrote a simple test extension to change how encumbrance is computed (attached to this post). It works if loaded in CoreRPG, but not in 4E. It looks like something is called too early with the 4E ruleset, let me explain what I found with some debugging.
To do the debugging, I copied CoreRPG ruleset, and modified the files to add some debug prints. I did the same on 4E, basing it on that test CoreRPG ruleset. Basically, all I changed, is adding some lines on some function that tell which function is called. For example, in scripts/manager_char_encumbrance.lua from CoreRPG:
local _bInitComplete = false;
function onInit()
Debug.console("[Core] Call to CharEncumbranceManager.onInit")
_bInitComplete = true;
end
I also modified those functions in scripts/manager_char_encumbrance.lua from CoreRPG:
local _bInitialized = false;
function performInit()
Debug.console("[Core] Call to performInit")
if not _bInitComplete then
return;
end
if CharEncumbranceManager.isEnabled() then
if _bInitialized then
return;
end
Debug.console("[Core] Do the actual friggin performInit")
OptionsManager.registerOptionData({ sKey = "CURR", sGroupRes = "option_header_houserule", tCustom = { default = "on", }, });
if Session.IsHost then
OptionsManager.registerCallback("CURR", CharEncumbranceManager.onCurrencyOptionUpdate);
CurrencyManager.registerCallback(CharEncumbranceMa nager.onCurrencyUpdate);
CharEncumbranceManager.enableEncumbranceHandlers() ;
CharEncumbranceManager.updateAllCharacters();
end
_bInitialized = true;
end
end
local _fnEncumbranceCalc = nil;
function addCustomCalc(fnEncumbranceCalc)
Debug.console("[Core] Call to addCustomCalc")
if _bInitialized then
Debug.console("[Core] addCustomCalc stopped, initialization already finished")
ChatManager.SystemMessage("CharEncumbranceManager.addCustomCalc must be called in global script onInit function.")
return;
end
_fnEncumbranceCalc = fnEncumbranceCalc;
CharEncumbranceManager.performInit();
end
Here is what I get with CoreRPG, just loading a blank campaign, creating a character, and adding elements to the inventory to have encumbrance calculations:
64855
Here is what I get with 4E in a similar scenario:
64856
As we can see, on CoreRPG, the call to performInit for Core's addStandardCalc is done before the call to CharEncumbranceManager.onInit, so that in this call to performInit, _bInitComplete is false, and prevents the proper initialization. Thus, when the extensions calls addCustomCalc, the actual initialization is done with the extension's custom function.
With 4E, however, the call to CharEncumbranceManager.onInit is done too early, so that 4E's call to performInit performs the initialization, and puts the flag _bInitialized to true, so that when the extension laters calls for addCustomCalc, performInit returns before doing its job.
Could you confirm this is a problem with the ruleset? If not, what am I doing wrong?
If it is indeed unexpected behavior, would there be a workaround? I can't find in the 4E ruleset where that early call to CharEncumbranceManager.onInit stems from...
Thanks in advance!
Facjad
I wrote a simple test extension to change how encumbrance is computed (attached to this post). It works if loaded in CoreRPG, but not in 4E. It looks like something is called too early with the 4E ruleset, let me explain what I found with some debugging.
To do the debugging, I copied CoreRPG ruleset, and modified the files to add some debug prints. I did the same on 4E, basing it on that test CoreRPG ruleset. Basically, all I changed, is adding some lines on some function that tell which function is called. For example, in scripts/manager_char_encumbrance.lua from CoreRPG:
local _bInitComplete = false;
function onInit()
Debug.console("[Core] Call to CharEncumbranceManager.onInit")
_bInitComplete = true;
end
I also modified those functions in scripts/manager_char_encumbrance.lua from CoreRPG:
local _bInitialized = false;
function performInit()
Debug.console("[Core] Call to performInit")
if not _bInitComplete then
return;
end
if CharEncumbranceManager.isEnabled() then
if _bInitialized then
return;
end
Debug.console("[Core] Do the actual friggin performInit")
OptionsManager.registerOptionData({ sKey = "CURR", sGroupRes = "option_header_houserule", tCustom = { default = "on", }, });
if Session.IsHost then
OptionsManager.registerCallback("CURR", CharEncumbranceManager.onCurrencyOptionUpdate);
CurrencyManager.registerCallback(CharEncumbranceMa nager.onCurrencyUpdate);
CharEncumbranceManager.enableEncumbranceHandlers() ;
CharEncumbranceManager.updateAllCharacters();
end
_bInitialized = true;
end
end
local _fnEncumbranceCalc = nil;
function addCustomCalc(fnEncumbranceCalc)
Debug.console("[Core] Call to addCustomCalc")
if _bInitialized then
Debug.console("[Core] addCustomCalc stopped, initialization already finished")
ChatManager.SystemMessage("CharEncumbranceManager.addCustomCalc must be called in global script onInit function.")
return;
end
_fnEncumbranceCalc = fnEncumbranceCalc;
CharEncumbranceManager.performInit();
end
Here is what I get with CoreRPG, just loading a blank campaign, creating a character, and adding elements to the inventory to have encumbrance calculations:
64855
Here is what I get with 4E in a similar scenario:
64856
As we can see, on CoreRPG, the call to performInit for Core's addStandardCalc is done before the call to CharEncumbranceManager.onInit, so that in this call to performInit, _bInitComplete is false, and prevents the proper initialization. Thus, when the extensions calls addCustomCalc, the actual initialization is done with the extension's custom function.
With 4E, however, the call to CharEncumbranceManager.onInit is done too early, so that 4E's call to performInit performs the initialization, and puts the flag _bInitialized to true, so that when the extension laters calls for addCustomCalc, performInit returns before doing its job.
Could you confirm this is a problem with the ruleset? If not, what am I doing wrong?
If it is indeed unexpected behavior, would there be a workaround? I can't find in the 4E ruleset where that early call to CharEncumbranceManager.onInit stems from...
Thanks in advance!
Facjad