DICE PACKS BUNDLE
  1. #1
    Xarxus's Avatar
    Join Date
    Mar 2019
    Location
    Rome (Italy)
    Posts
    242

    DB personalized node - GM/player differences

    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:
    Code:
    <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
    Code:
    Interface.openWindow("testrecord", "test." .. User.getUsername() );
    Looking at the DB everything seems fine while the GM uses it. In fact I get:
    Code:
    <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.
    FGU ULTIMATE License
    Click here for RPG Music or here for Dwarves songs on Spotify

  2. #2
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,246
    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.atlassia...3/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" />
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  3. #3
    Xarxus's Avatar
    Join Date
    Mar 2019
    Location
    Rome (Italy)
    Posts
    242
    Ty @Trenloe, thanks to your suggestions I solved adding this code to my ruleset manager:
    Code:
    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
    FGU ULTIMATE License
    Click here for RPG Music or here for Dwarves songs on Spotify

  4. #4
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,246
    Quote Originally Posted by Xarxus View Post
    Ty @Trenloe, thanks to your suggestions I solved adding this code to my ruleset manager:
    Code:
    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!
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
FG Spreadshirt Swag

Log in

Log in