1. #1

    Linking a control to a DB node with a script

    Hi there,

    I have created a window which needs to display some player info stored in the DB. Right now, I am using an OnInit() script that populates the controls with the DB data and an OnClose() script that update the DB when the window close.

    It works but I was wondering if there was not a more efficient way of doing this by using something closer to the source tag which basically link the control directly to the tag and would avoid having to run an OnClose script to update the DB ?

    Any tip ?

  2. #2
    damned's Avatar
    Join Date
    Mar 2011
    Location
    Australia
    Posts
    18,866
    Blog Entries
    1
    Screenshot?
    If its only displaying that players data to that player - just set the source to be the charsheet data.
    Otherwise look at DB.addHandler

    MoreCore - Generic Ruleset
    --- Projects ---
    Extensions | Tutorials | MoreCore | MoreCore Themes | Call of Cthulhu | Maelstrom | FG Con

  3. #3
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Denver, Colorado, USA (for a bit)
    Posts
    23,343
    The FG "field" controls are specifically designed to be sourced on database fields. It sounds like you're completely re-inventing functionality that is actually there already. When you open a window, there are 2 things it usually needs - a windowclass (required) and a database source (optional, but usually necessary when using database fields) - I'd say over 99% of FG windows have a database source.

    Then, by default, the field controls are matched to a database field of the same name - so a string control called "name" would source it's data from the database field "name" at the window datasource level. If you don't want to use the control name as the database fieldname to use, you can add the database source to the control using the "source" property in the control's definition: source="<DB path realtive to the window datasource>l"

    For example, in the 3.5E character sheet, the field that displays the current AC total for that character record is: <number_chartotalac name="ac" source="ac.totals.general">


    FG Product Development status: Pathfinder Playtest Ruleset and add-ons: In development. Pathfinder Bestiary, Pathfinder Bestiary 2, Pathfinder Bestiary 3 (in store).

    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!

  4. #4
    That is how I run my character sheet but the window I am creating is meant to be a template used by multiple players simultaneously. Let's assume that this window needs to display the name of the character which is lineked to the "name" node of the said player in the DB.
    If I write something like <Stringfield name="name" source="name"> how does FG know which player I am talking about ?

  5. #5
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Denver, Colorado, USA (for a bit)
    Posts
    23,343
    Quote Originally Posted by Tabulazero View Post
    That is how I run my character sheet but the window I am creating is meant to be a template used by multiple players simultaneously. Let's assume that this window needs to display the name of the character which is lineked to the "name" node of the said player in the DB.
    If I write something like <Stringfield name="name" source="name"> how does FG know which player I am talking about ?
    Open the window with a different "datasource" node for each player.

    Character sheets are (usually, depending on which ruleset you're using) stored in the database charsheet.id-XXXXX database node. The first PC sheet would be charsheet.id-00001 the second charsheet.id-00002, etc.. When the window is opened, set the relevant database node as the window datasource. Then the "name" control will look at charsheet.id-00001.name for the window opened with the first character sheet datasource, charsheet.id-00002.name for the second, etc..
    Last edited by Trenloe; July 12th, 2019 at 22:45. Reason: Corrected charsheet DB node


    FG Product Development status: Pathfinder Playtest Ruleset and add-ons: In development. Pathfinder Bestiary, Pathfinder Bestiary 2, Pathfinder Bestiary 3 (in store).

    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!

  6. #6
    Is there a way to pass chargen.id-00001.name as a source via a script ?

    I want to create only one window class and be able to pass it chargen.id-00001.name and then if a second player also launches the window to pass it chargen.id-00002.name ?

  7. #7
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Denver, Colorado, USA (for a bit)
    Posts
    23,343
    Quote Originally Posted by Tabulazero View Post
    Is there a way to pass chargen.id-00001.name as a source via a script ?
    Yes, absolutely.

    Quote Originally Posted by Tabulazero View Post
    I want to create only one window class and be able to pass it chargen.id-00001.name and then if a second player also launches the window to pass it chargen.id-00002.name ?
    You have control over what the window datasource is when it's launched. How are you opening the window?


    FG Product Development status: Pathfinder Playtest Ruleset and add-ons: In development. Pathfinder Bestiary, Pathfinder Bestiary 2, Pathfinder Bestiary 3 (in store).

    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!

  8. #8
    A quick screen capture to illustrate what I am trying to do.

    2019-07-12.png

    I open the diceroller sheet by doublecliking on the character sheet. Do I just need to pass the chargen.id-00001 to the window I am opening via a Interface.openWindow("rollerwindow") command and FG will know which child node to pick ?

  9. #9
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Denver, Colorado, USA (for a bit)
    Posts
    23,343
    Quote Originally Posted by Tabulazero View Post
    Do I just need to pass the chargen.id-00001 to the window I am opening via a Interface.openWindow("rollerwindow") command and FG will know which child node to pick ?
    Yup.

    Just pass in charsheet.id-00001 (or whatever id-XXXXX node you need) to Interface.openWindow and then if you have a field control called "name" it will populate that field with the data from charsheet.id-00001.name

    Sorry, earlier I mentioned chargen as the character sheet node, it's actually charsheet - sorry about that. I'm deep in chargen ruleset code at the moment and have it on the brain!


    FG Product Development status: Pathfinder Playtest Ruleset and add-ons: In development. Pathfinder Bestiary, Pathfinder Bestiary 2, Pathfinder Bestiary 3 (in store).

    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)

Posting Permissions

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

Log in

Log in