PDA

View Full Version : Module.activate() Not Working on Client



Mike Serfass
February 21st, 2024, 01:20
I have an extension with a block of code that activates a few modules on the host and client on startup.
At some point the client side stopped working. I noticed it recently when I added a new module and the players said they didn't see it.
In testing, I confirmed that the Module.activate works on the host machine but not the client for all modules.
Permissions are set correctly on the host. On the client, in the Module Activation window, looking at the list of available modules, all the modules show as available and loadable. The player can manually load all the modules, so it's not permissions.

Here's my block of code:


for _,modules in ipairs(moduleset) do
for _,module in ipairs(modules.modules) do
local info = Module.getModuleInfo(module.name)
if info and not info.loaded then
Module.activate(module.name)
Debug.console(module.name .. " post-activate: loaded", info.loaded, "loading", info.loading, "permission", info.permission)
end
end
end


I added a debug line. On the host machine it emits this:


[2/20/2024 8:02:31 PM] s'SWADE Player Guide post-activate: loaded' | bFALSE | s'loading' | bFALSE | s'permission' | s'allow'
[2/20/2024 8:02:31 PM] s'Quar Dai - Player post-activate: loaded' | bFALSE | s'loading' | bFALSE | s'permission' | s'allow'
[2/20/2024 8:02:32 PM] s'SWADE Effects post-activate: loaded' | bFALSE | s'loading' | bFALSE | s'permission' | s'allow'
[2/20/2024 8:02:32 PM] s'SWADE Adventure Deck post-activate: loaded' | bFALSE | s'loading' | bFALSE | s'permission' | s'allow'
[2/20/2024 8:02:32 PM] s'Mike's Random Tables post-activate: loaded' | bFALSE | s'loading' | bFALSE | s'permission' | s'allow'
[2/20/2024 8:02:32 PM] s'Quar Dai Adventure Deck post-activate: loaded' | bFALSE | s'loading' | bFALSE | s'permission' | s'allow'


On the client machine it emits this:


[2/20/2024 8:03:19 PM] s'SWADE Player Guide post-activate: loaded' | bFALSE | s'loading' | bFALSE | s'permission' | s'disallow'
[2/20/2024 8:03:19 PM] s'Quar Dai - Player post-activate: loaded' | bFALSE | s'loading' | bFALSE | s'permission' | s'disallow'
[2/20/2024 8:03:19 PM] s'SWADE Effects post-activate: loaded' | bFALSE | s'loading' | bFALSE | s'permission' | s'disallow'
[2/20/2024 8:03:19 PM] s'SWADE Adventure Deck post-activate: loaded' | bFALSE | s'loading' | bFALSE | s'permission' | s'disallow'
[2/20/2024 8:03:19 PM] s'Mike's Random Tables post-activate: loaded' | bFALSE | s'loading' | bFALSE | s'permission' | s'disallow'
[2/20/2024 8:03:19 PM] s'Quar Dai Adventure Deck post-activate: loaded' | bFALSE | s'loading' | bFALSE | s'permission' | s'disallow'


Of note is the fact that all these modules are loaded on the host, yet it indicates they're not loaded and enters the if block, after which loaded is still false.
None of these modules are loaded on the client machine, but they're installed.

I even added a block for the host to set permissions. That made no difference.


if Session.IsHost then
moduleset = aDataModuleSet["client"]
for _,modules in ipairs(moduleset) do
for _,module in ipairs(modules.modules) do
Module.setModulePermissions(module.name, "allow")
end
end
end



Did something change?
Thanks in advance.

LordEntrails
February 21st, 2024, 16:11
MOD: moved to Workshop since this is better addressed as a community developer question.

Moon Wizard
February 21st, 2024, 19:26
When are you triggering the load on the player client? onInit, onTabletopInit, onDataLoaded?

Regards,
JPG

Mike Serfass
February 22nd, 2024, 20:47
I'm calling it from OnInit for both host and client.
Should I use one of the other events for either or both?
Thanks!

Mike Serfass
February 22nd, 2024, 21:58
I tried a few things based on your suggestion.
The onDataLoaded event never fires.
The onTabletopInit fires after all the modules load, but that had the same results as onInit. If that's a better place to put Module.activate I'll keep it there.
I put Debug.console on the lines just before and just after Module.activate.
Module.activate is being called from the host, but it's not activating the modules.
When I check the module info, it shows permission set to 'disallow'.
The problem isn't where I'm calling Module.activate, it's that the modules have the wrong permission set on the host.
I double checked that the module permissions are set correctly.
They're correct on the host and the client.
While initializing, the client indicates permission is disallow, but in the Module Activation window, those modules are listed and I can manually load them.
Somewhere between initializing and the activation window displaying, permissions are set correctly.
Shouldn't those permissions be set correctly from the outset? They used to be, because this code worked before.

Thank you for the help!

Mike Serfass
February 22nd, 2024, 22:05
As a note, I use the Desktop.addDataModuleSet method to add a button to the campaign setup.
That works fine. The button appears, and when the player clicks it, all the modules load as expected.
The modules just don't load from Module.activate on init.
I think this points back to the permissions being set wrong, or not being set from the host before the init events fires, more likely.

Moon Wizard
February 23rd, 2024, 02:29
My apologies, you can register an event to be notified when all the data has loaded. Example from WindowSaveManager in CoreRPG:


function onTabletopInit()
if OptionsManager.isOption("WSAV", "on") then
DB.addEventHandler("onDataLoaded", WindowSaveManager.onDataLoaded);
end
end
function onDataLoaded()
...
end


You will definitely need to wait until onTabletopInit call or onDataLoaded event to check.

Regards,
JPG

Mike Serfass
February 23rd, 2024, 18:43
I added the event and moved the code to the onDataLoaded callback.
That did it! Thank you.
It's an important note that accessibility of modules is not set until later in the client startup process.
Thank you Moon Wizard.

Moon Wizard
February 23rd, 2024, 18:51
Yeah, I had a similar situation, where saved windows couldn't be restored for campaign data, because it hadn't been streamed in yet from host. Thus, I added a new event to help with that. Glad it helped you too.

Regards,
JPG