DICE PACKS BUNDLE
  1. #1

    create new list item from lua script

    I am trying to add an item to the character's inventory list from a script that is not within the campaigns folder.
    Does anyone have an example of how this is done?

    It seems like createWindow() is used in campaign/scripts but that doesn't work in regular scripts.
    I have an idea to look for maximum ID # in inventorylist and then title the new node as that number + 1, but this seems like an over-complicated approach.

    PF1e ruleset

  2. #2
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,362
    Yep, use <windowlist>.createWindow()

    https://fantasygroundsunity.atlassia...t#createWindow

    The key here is that you'll need to get the instance of the windowlist control to be able to use that API command.

    It is often better to create a new DB child, which will have a similar effect, but can be better going direct to the database (and a repeatable location once you have nodeChar) than worrying about working out how to navigate the GUI hierarchy to get the windowlist control instance.
    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
    Quote Originally Posted by Trenloe View Post
    It is often better to create a new DB child, which will have a similar effect, but can be better going direct to the database (and a repeatable location once you have nodeChar) than worrying about working out how to navigate the GUI hierarchy to get the windowlist control instance.
    This is actually what I was meaning. I just don't know how to give it the correct name (id-00001 vs id-00002 and so forth). Does it do that automatically if I don't specify a name?

    EDIT: yes it does
    Thanks Trenloe.
    Last edited by bmos; September 22nd, 2020 at 01:33.

  4. #4
    When you use DB.createChild() it will automatically add a new id# in the sequence. So example:

    Say we want to script in adding a new character sheet, but want it to have a certain charisma bonus each time. So the DB in dot notation would look like this, charsheet.#.abilities.charisma.bonus. The '#' is the id# of each character sheet in the campaign/module structure. Since we don't need to assign it a name FG assigns it a id# in sequence. So if I go to the root and then run DB.createChild() on charsheet, it will then create nodes with the id# sequence (id-00001 .. id-00002 .. id-00003). So yes, it will add it in automatically and you see this behavior across the DB within the campaign as FG doesn't create meaningful names for list nodes.
    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

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