Page 1 of 1

[2.1.7] Peculiar loading behavior

Posted: Fri Jul 10, 2026 10:23 pm
by Morganite
I'm currently in the process of updating the unofficial BZ mod forks to 2.1, and I noticed something that seemed unexpected.

These all make use of the common library "bzlib", but it's accessed in what I suppose is a slightly unusal way. Each mod has a file named data-util.lua, which has these contents:

local me = require("me")
local util = require("__bzlib__/data-util");
util.initialize(me)
return util


me.lua contains mod-specific data and functions; it returns an object that gets assigned to util.me. So far, so good. When one of the mods needs to use something from bzlib, it goes

local util = require("data-util")

And then calls values on util as normal. (Including, frequently enough, util.me.)

This all works fine on 2.0. And on 2.1.7 (or 2.1.9) it works fine if only one of these mods is loaded at a time. But once I tried having both bzcarbon2 and bzfoundry2 active at once (those being the first two of these mods I tried updating), it gives an error message. Specifically,

2.872 Error ModManager.cpp:1768: Failed to load mod "bzfoundry2": __bzfoundry2__/foundry-updates.lua:4: attempt to call field 'enable' (a nil value)
stack traceback:
__bzfoundry2__/foundry-updates.lua:4: in main chunk
[C]: in function 'require'
__bzfoundry2__/data-updates.lua:1: in main chunk


Now, the me.enable function is defined in bzfoundry2's me.lua, and works just fine on it's own. But adding a debug print showed that when both mods are enabled, util.me ends up containing the contents produced by me.lua in bzcarbon2, despite that having been assigned by and in another mod to local variables.

Adding another copy of
local me = require("me")
util.initialize(me)


after the require line the first time util is used in data-updates (and presumably data-final-fixes, but I haven't tested that far) seems to fix it for the rest of the phase, but since that should have already been done once, it really does not seem like this should be happening. I'm told that in 2.1 the game is caching file requires, but should they be contaminating each other across different mods this way?

Edit: Added log

Re: [2.1.7] Peculiar loading behavior

Posted: Fri Jul 10, 2026 11:37 pm
by Rseding91
Data stage is one shared lua state across all mods.

Re: [2.1.7] Peculiar loading behavior

Posted: Sat Jul 11, 2026 12:11 am
by Morganite
Even for local variables? If those persist it... actually I'm still very confused, but it almost sounds like it makes sense... but then what's the real difference between using a local and a global? Since me.lua always returns what it should, I would think changing the variable names in one copy of data-util.lua should prevent clobbering, but that does not seem to be the case...

Re: [2.1.7] Peculiar loading behavior

Posted: Sat Jul 11, 2026 12:15 am
by Rseding91
This sounds identical to 134270

Re: [2.1.7] Peculiar loading behavior

Posted: Sat Jul 11, 2026 12:47 am
by Morganite
Hmmm. That one used globals, but I guess two mods requiring the same file from a third mod has the same effect?

I was able to work around this by changing return util to return table.deepcopy(util).