5E Character Create Playlist
Page 1 of 2 12 Last
  1. #1

    Trying to Reference a Control on a Sibling Window

    I have a checkbox on a window -- charsheet_main -- and I'm trying to get that checkbox to also tick another checkbox on a different window -- charsheet_abilities -- when its value is set to checked.

    I'm using Ruleset Wizard and building the project off of the CoreRPG ruleset and I can't figure out how to dereference and get the correct reference point for the checkbox on the charsheet_abilities window.

    I know from the CoreRPG ruleset that I'm working off of this model:
    Code:
    <root>
       <windowclass name="charsheet">
          <sheetdata>
             <sub_charsheet_overview name="overview"/>
             <sub_charsheet name="main">
                 <class>charsheet_main</class>
             </sub_charsheet>
             <sub_charsheet name="abilities">
                 <class>charsheet_abilities</class>
             </sub_charsheet>
             <sub_charsheet name="inventory">
                 <class>charsheet_inventory</class>
             </sub_charsheet>
             <sub_charsheet name="notes">
                 <class>charsheet_notes</class>
             </sub_charsheet>
          </sheetdata>
    So I know there's a parent window 'charsheet' and it has the window I'm working from 'charsheet_main' and I can see there's the sibling node 'charsheet_abilities', but I can't navigate to it and grab the control I want to edit.

    Here's everything I have tried in the context of the charsheet_main window. Results are after the ';' :
    Code:
      --Debug.chat(window.getDatabaseNode().getName()); = id-00001
      --Debug.chat(window.getDatabaseNode().getParent().getName()); = charsheet
      --Debug.chat(window.getDatabaseNode().getParent().getChild('id-00002')); = nil
      --Debug.chat(window.getDatabaseNode().getParent().getControls()); = nil
      --Debug.chat(parentcontrol.getName()); = nil
      --Debug.chat(window.parentcontrol); subwindow = {name = s'main',x,y,w,h = 15,20,695,508}
      --Debug.chat(window.subwindow); nil
      --Debug.chat(window.parentcontrol.getName()); s'main'
      --Debug.chat(window.parentcontrol.window.parentcontrol); nil
      --Debug.chat(window.getDatabaseNode().getParent().parentcontrol.getName()); nil
      --Debug.chat(window.getDatabaseNode().getParent().subwindow); nil
      --Debug.chat(window.getDatabaseNode().getParent()); databasenode = {charsheet}
      --Debug.chat(window.getDatabaseNode().getParent().getChildCategories()); { }
      --Debug.chat(window.getDatabaseNode().getParent().getChildList()); {#1 = databasenode = { charsheet.id-00001 }}
      --Debug.chat(window.getDatabaseNode().getParent().getNodeName()); s'charsheet'
      --Debug.chat(window.getDatabaseNode().getParent().getPath()); s'charsheet'
      --Debug.chat(window.getDatabaseNode().getNodeName()); s'charsheet.id-00001'
      --Debug.chat(window.linguistics_checkbox.getValue()); error nil index attempt
      --Debug.chat(window.getDatabaseNode().getText()); blank
      --Debug.chat(window.getDatabaseNode().getType()); s'node'
      --Debug.chat(window.getDatabaseNode().getValue()); nil
      --Debug.chat(window.getDatabaseNode().getParent().getControls()); nil method
    What I'm confused by is that when I attempt to navigate to charsheet_main from the charsheet_abilities window, I get that both siblings are on the same node somehow:
    Code:
      --Debug.chat(window.parentcontrol.getName()); s'abilities'
      --Debug.chat(window.getDatabaseNode().getParent().getPath()); s'charsheet'
      --Debug.chat(window.getDatabaseNode().getNodeName()); s'charsheet.id-00001'
    Specifically, both windows say they are on node: charsheet.id-00001, but I get different getName() results depending upon which window I'm executing from.

    I know from playing the 5E ruleset that you can edit controls on other windows via actions on a separate window: Submitting a class for a new character allows you to choose starting skills which then update the checkboxes under the skills section -- pretty much exactly what I'm trying to do. I just can't find any good information on the developer guides for what I'm supposed to do.

  2. #2
    You're better off updating the database node; and letting the checkbox update itself based on the value change.

    Otherwise, you end up having to traverse up/down window hierarchies, which makes the code harder to modify later.

    Regards,
    JPG

  3. #3
    Quote Originally Posted by Moon Wizard View Post
    You're better off updating the database node; and letting the checkbox update itself based on the value change.

    Otherwise, you end up having to traverse up/down window hierarchies, which makes the code harder to modify later.
    I'm not sure what you mean by this: I've only been doing ruleset creation and ruleset wizard for about 10 hours -- so I'm very new.

    Looking at the https://fantasygroundsunity.atlassia...2/databasenode databasenode documentation, do you mean that I should use setValue() to hold some variable I can check, or perhaps I could use setState() as a boolean check, or do you mean I should create a child node that could hold reference data somehow?

  4. #4
    If you have the character top-level node from the top-level window, you can use DB.setValue(<character node>, <field path>, "number", <desired value>) to set the value to 0 or 1, depending on whether you want the checkbox set to 0 or 1. This is assuming that you are using the CoreRPG version of the "button_checkbox" template for your checkbox, which uses a "number" field in the database.

    I don't use ruleset wizard at all, as it's not an official tool, but a community project.
    I highly recommend opening up both the CoreRPG and 5E rulesets into a folder and reviewing their contents to see examples of how things are done in the primary rulesets.

    Also, try turning on "/debug on" when within an existing ruleset to get hover information on the window/field you are over.

    Regards,
    JPG

  5. #5
    I don't think I'm correctly grasping how I can get the information I need based on the documentation. I'm trying to use DB.getPath() to find and spit out the path notation from a given 'node' to a specified control so I can use that path with the DB.setValue(); but it just seems to spit out whatever I enter into it with a period between them:

    Code:
    --the window is called 'charsheet'
    --a sub window on charsheet is called 'charsheet_main' and resolves to a node called 'id-00001'
    --the sub window id-00001 has controls on it called 'teamster_class_checkbox' and 'android_class_checkbox'
    
    --EXPECTING: s'id-00001.teamster_class_checkbox'
    Debug.chat(DB.getPath('id-00001', 'teamster_class_checkbox')); --spits out: s'id-00001.teamster_class_checkbox'
    
    --EXPECTING: s'charsheet.id-00001.teamster_class_checkbox'
    Debug.chat(DB.getPath('charsheet', 'teamster_class_checkbox')); --spits out s'charsheet.teamster_class_checkbox'
    
    --EXPECTING: s'charsheet.id-00001.android_class_checkbox'
    Debug.chat(DB.getPath('charsheet', 'android_class_checkbox')); --spits out: s'charsheet.android_class_checkbox'

    https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644582/DB

  6. #6
    It depends on the context of where the script is running (global script, window class script, control/template script). Like I was mentioning before, you're best off looking at examples in working rulesets.

    You shouldn't be calling paths directly, because you can't assume which character path you're looking at without context. If you're in a window class script, you can use getDatabaseNode() or getDatabasePath() to get the window data source node. If you're in a control script, you can use window.getDatabaseNode() or window.getDatabasePath() to get the parent window data source node. If you're in a global script, you need to pass the character node as a parameter into the global script function.

    In your example above, I'm unclear where you think that the id-00001 would come from in your examples. DB.getPath merely builds a path from the given information. There's no other context.

    Perhaps you should provide an example of the class/template/script where this is running, instead of code snippets?

    Regards,
    JPG

  7. #7
    I've made some good progress, so for the sake of posting a resolution to this thread I'll go through each item:

    First off, if I understand your post correctly, then all DB.getPath() does is combine what you give it -- which seems useless -- so I'm betting I still don't understand how to use it.

    If I understand your quote correctly, I think this was how I got 'id-00001': I ran Debug.chat(window.getDatabaseNode().getName()); within a checkbox control to determine that the sub-window 'charsheet_main' was being called 'id-00001' by the database.
    If you're in a control script, you can use window.getDatabaseNode() or window.getDatabasePath() to get the parent window data source node.
    SOLUTION: Because I didn't know how to get a path using any path functions -- as I still don't know how they work -- I used a bunch of inline debug calls on various iterations of window.getDatabasenode().lotsofotherthings to determine what I guessed to be the path I needed and on a whim I entered it into the code I needed the path for and it worked:
    Code:
    DB.setValue('charsheet.id-00001.mechanical_repair_checkbox', 'number', 1);
    That essentially breaks down to 'window.subwindowid.controlname'.

    I'd like to provide an example, but I wouldn't know where to start and stop -- I thought the previous code snippets I sent were complete enough -- I don't understand what information would be valuable in the context of assisting with my issue. I think there are 4 files involved because I'm using the CoreRPG as an imported ruleset and merging behavior off of its templates. I'm using the CoreRPG record_char.xml and modifying it with my own charsheet.xml, charsheet_main.xml, and charsheet_abilities.xml. The record_char.xml references 'charsheet_main' and 'charsheet_abilities' as sub-windows in the template, but I had trouble tracking down the details in the CoreRPG files -- as much as I know it mainly allows me to use the CoreRPG's tab behavior without having to make it myself.

    So that's where the path logic I used came from to navigate to the control I needed: parentwindow(charsheet) -> some sort of child node that held both the sub windows 'main' and 'abilities' but only had 1 id for both windows(id-00001) -> control(mechancial_repair_checkbox)

    If you can shed any light on things I don't understand or am being straight up stupid about, I'd appreciate it; but my initial issue has been resolved: I can now update controls on other windows from a script on a sibling window.

    Thanks for the help!

  8. #8
    Every character is an individual record under the "charsheet" master node. By default, all character node names are created dynamically, which means they will be of the form charsheet.id-00001, charsheet.id-00002, and so on. Try creating several characters in an empty CoreRPG campaign to see an example of basic records stored in the db.xml for that campaign. Make sure to give them each unique names, so you can see how the data is stored.

    When you are working on scripts within a character sheet, then you use getDatabaseNode() [in window class scripts] or window.getDatabaseNode() [in control scripts], in order to get the "current" character record that you are working with. You can't hard-code the paths, because they will be unique to each character record and sensitive to the window context you are running your script in.

    For example, within a "charsheet" window class script (based on CoreRPG), you could call DB.getValue(getDatabaseNode(), "name", "") to get the current character name; or DB.setValue(getDatabaseNode(), "name", "string", "Test Character") to set the current character name. That's a simple example that you probably would never use; but it shows how you can get the current sheet database node, and assign data within that path. (i.e. DB.setValue(getDatabaseNode(), "mechanical_repair_checkbox", "number", 1))

    Regards,
    JPG

  9. #9
    Ah, that does point out quite a flaw in my logic.

    That breakdown of how the scope of getDatabaseNode() works really helped! I ran some tests with a player and saw that all my scripts only worked on the first character sheet generated in the campaign.

    I've since modified it and it's working with multiple character sheets now:
    Code:
    local thisnode = window.getDatabaseNode();
     
    if {condition} then
      DB.setValue(thisnode, 'zero_g_checkbox', 'number', 0);

  10. #10
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,416
    Quote Originally Posted by Inoto View Post
    First off, if I understand your post correctly, then all DB.getPath() does is combine what you give it -- which seems useless -- so I'm betting I still don't understand how to use it.
    At first look DB.getPath can appear to be just concatenating strings. The power of DB.getPath becomes apparent when you consider data module records - e.g. item.id-00001@MyModule - DB.getPath inserts alterations to the base path within the structure correctly - whether the record is within the campaign or a module.

    For example:

    Code:
    local sMyPath = DB.getPath(getDatabaseNode(), "description");
    If getDatabaseNode() was item.id-00001 (a campaign record) then sMyPath = item.id-00001.description. But if getDatabaseNode() was item.id-00001@MyModule (a data module record) then sMyPath = item.id-00001.description@MyModule

    The power of DB.getPath is that you don't need to code to check if the database record is a campaign record or a module record, the API function does that for you.
    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)

Tags for this Thread

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
  •  
STAR TREK 2d20

Log in

Log in