DICE PACKS BUNDLE
  1. #1

    Join Date
    Sep 2020
    Location
    Ballston Lake, NY
    Posts
    608

    masterindex_buttons Button DB Node

    If I add a button using
    Code:
    LibraryData.addIndexButton("npc", "button_makenpc")
    how do I get the DB node of the list window that button is on?

    I add this button to the NPCs list window.
    I want the "npc" node in db.xml. I'd like to use
    Code:
    window.getDatabaseNode().getNodeName()
    rather than hard-coding "npc".

    But
    Code:
    window.getDatabaseNode()
    returns nil, because window is an instance of masterindex_buttons.
    I need the container of masterindex_buttons but I can't figure out how to get it.


    Thanks for the help.

  2. #2
    The npc node is a parent node under the root in the database. The quick and not secure way is to useDB.findNode("npc") or DB.createNode("npc") to access the parent node. You can also use LibraryData.getRootMapping("npc") as well to get the string instead of the node and then throw the return into DB.findNode or DB.createNode
    Dominic Morta
    Ruleset Developer
    Smiteworks

    How to zip up your campaign if the Developers ask for it-How to zip up your campaign if the Developers ask for it

    How to provide an Unity Connection issue?-Connection Issues and What to Provide

    Unity Updater issue?-Updater Issues

    Classic and Unity Port Forwarding?-Fantasy Grounds Connections Explained

    Comcast or Cox ISP User?-Comcast XFinity and Cox Users

    Have a suggestion?-Feature Request

  3. #3

    Join Date
    Sep 2020
    Location
    Ballston Lake, NY
    Posts
    608
    The issue is getting the node a list window is bound to; the node for which it's listing items.
    In this case, I know the "npc" node is the one being used.
    If I want to write shared code for a button that can be put on any list window, I need to use getDatabaseNode. Otherwise, I use an unbound button template then have specific overridden buttons for each list window I use it on.
    If a node name in db.xml changes, the button breaks until I change the hard-coded value.
    It seems I can't use getDatabaseNode any longer in some cases with the recent update.
    I can't figure out how to get to the container, which does have a bound node I can reference with getDatabaseNode.

    Thanks for the LibraryData.getRootMapping("npc"). I didn't know about that function. Still, I need to know the node ahead of time and hard code that parameter. But I suspect that will catch node name changes in db.xml.

  4. #4
    Well if you are in the window itself, then you can look at the masterindex_window.lua script file as that has the functions available that can assist. The one that comes to mind would get getRecordType() if you are generalizing the code. This will return the root type that can be used in the other function calls I listed.
    Dominic Morta
    Ruleset Developer
    Smiteworks

    How to zip up your campaign if the Developers ask for it-How to zip up your campaign if the Developers ask for it

    How to provide an Unity Connection issue?-Connection Issues and What to Provide

    Unity Updater issue?-Updater Issues

    Classic and Unity Port Forwarding?-Fantasy Grounds Connections Explained

    Comcast or Cox ISP User?-Comcast XFinity and Cox Users

    Have a suggestion?-Feature Request

  5. #5

    Join Date
    Sep 2020
    Location
    Ballston Lake, NY
    Posts
    608
    I'm not in masterindex_window. That's the problem.
    I'm in masterindex_buttons.
    Code:
    Debug.chat("window", window)
    returns
    s'window' | windowinstance = { class = masterindex_buttons, node = nil, x,y,w,h = 0,0,430,27 }

    Here's the button:
    Code:
    <template name="button_makenpc">
    	<button_text_hotkey>
    		<anchored to="buttonanchor" width="70">
    			<top />
    			<left anchor="right" relation="relative" offset="5" />
    		</anchored>
    		<state>
    			<textres>npc_button_makenpc</textres>
    		</state>
    		<tooltip textres="tooltip_makenpc" />
    		<type>makenpc</type>
    		<icon>button_export</icon>
    		<script>
    			function onButtonPress()
    				-- this returns masterindex_buttons
    				Debug.console("window", window)
    				-- this is the call I want to make; but it returns nil and errors
    				--NPCMaker.makeNPCFromClipboardData(window.getDatabaseNode().getNodeName())
    				-- this is the call I have to make for it to work
    				NPCMaker.makeNPCFromClipboardData("npc")
    			end
    		</script>
    	</button_text_hotkey>
    </template>

  6. #6
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,470
    Assuming masterindex_buttons is a subwindow, then you can use parentcontrol (window.parentcontrol) to traverse up the GUI hierarchy. Mentioned here: https://fantasygroundsunity.atlassia...5196/subwindow
    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
  •  
5E Product Walkthrough Playlist

Log in

Log in