Log in

View Full Version : DB personalized node - GM/player differences



Xarxus
November 26th, 2023, 13:02
I would like to create a section of the DB in which we can save some specific information related to the game system that my friends and I are creating.

The structure should be this:
<test>
<playername1>
data
</playername1>
<playername2>
...
</playername2>
...
</test>

Each player should have access to their own section, of course. I have a windowclass which is opened with the statement
Interface.openWindow("testrecord", "test." .. User.getUsername() );
Looking at the DB everything seems fine while the GM uses it. In fact I get:
<test>
<GM>
data
</GM>
</test>But when a player uses it I get no errors, but the structure doesn't appear.

What am I doing wrong? Because I'm definitely doing something wrong.

Trenloe
November 26th, 2023, 13:31
I would imagine that if you look in the console.log file there will be a message/warning indicating that the player instance doesn't own the <test> node in the database. A player instance can only modifiy database nodes if they are a holder of that node.

I don't know if there's a better way to do this, but my recommendation would be code the creation of the base node that the windowclass "testrecord" in the GM instance when a player logs in to the campaign - you can use the User.onLogin hanlder: https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644683/User#onLogin

The GM instance should also make the player the "holder" of the new node - allowing that one user to change data under the node. You can see this in the db.xml for a campaign - have a look in the charsheet node - any PCs that are owned will have entry like this: <holder name="Trenloe" owner="true" />

Xarxus
November 26th, 2023, 14:49
Ty @Trenloe, thanks to your suggestions I solved adding this code to my ruleset manager:
function onTabletopInit()
User.addEventHandler("onLogin", MyRuleset.onClientLogin);
end

function onClientLogin(sUser, bActivated)
if bActivated then
local oUserNode = DB.createNode("test." .. sUser);
DB.setOwner(oUserNode, sUser);
end
end

Trenloe
November 26th, 2023, 17:02
Ty @Trenloe, thanks to your suggestions I solved adding this code to my ruleset manager:
function onTabletopInit()
User.addEventHandler("onLogin", MyRuleset.onClientLogin);
end

function onClientLogin(sUser, bActivated)
if bActivated then
local oUserNode = DB.createNode("test." .. sUser);
DB.setOwner(oUserNode, sUser);
end
end
Nice one!