PDA

View Full Version : Trying to alter client startup behavior using User.getOwnedIdentities



darrenan
June 3rd, 2024, 20:16
As the title says, I'm trying to change the client startup behavior to pop up the character selection window only if the User logging in currently has owned characters, and otherwise popup a different window on startup. Currently the code looks like this:


--
-- Please see the license.html file included with this distribution for
-- attribution and copyright information.
--

function onInit()
Desktop.onTabletopInit = onTabletopInit;
end
function onTabletopInit()
User.addEventHandler("onLogin", Desktop.onUserLogin);

if not Session.IsHost then
-- This user has any characters, then open the character selection window, otherwise open the playbook list.
aIdentities = User.getOwnedIdentities();

Debug.chat("Owned Identities:");
for _,sId in ipairs(aIdentities) do
Debug.chat(sId);
end

if #aIdentities == 0 then
Interface.openWindow("masterindex", "playbook");
else
Interface.openWindow("charselect_client", "");
end
end

Desktop.registerModuleSets();
if not CampaignRegistry or not CampaignRegistry.setup then
Interface.openWindow("setup", "");
end
end


(ignore the Debug. lines, that's just me trying to figure out what's going on). Currently, aIdentities always comes back empty, even after creating a character. Is this because the client doesn't have permissions to get that type of info? Is there something else I'm doing wrong here? I have also tried User.getActiveIdentities with the same results (I didn't expect that one to work since the user doesn't have any active identities on startup).

Moon Wizard
June 4th, 2024, 01:59
That API returns the character IDs that are currently "active" in the session. It is actually different than ownership, but that API is very old and was named before I joined the company. It hasn't been changed due to backward compatibility reasons.

You don't need to use DesktopManager.onTabletopInit = fn at all. The onTabletopInit function is called on every global script automatically once the desktop panels are all loaded.

To do something similar, you would have to iterate over the "charsheet" node to see what is owned once the data loading is complete.


function onTabletopInit()
DB.addEventHandler("onDataLoaded", onDataLoaded);
end
function onDataLoaded()
...
end


Regards,
JPG

darrenan
June 4th, 2024, 02:08
Thanks! I was overriding the corerpg function to suppress the display of the character list window. With your approach above, that would still happen right?

Moon Wizard
June 4th, 2024, 08:38
Ah, yeah, I get what you were doing there now. Your way is correct. Nothing to see here, carry on...

Regards,
JPG