PDA

View Full Version : create new list item from lua script



bmos
September 21st, 2020, 14:19
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

Trenloe
September 21st, 2020, 14:31
Yep, use <windowlist>.createWindow()

https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/4162373/windowlist#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.

bmos
September 22nd, 2020, 00:26
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.

superteddy57
September 22nd, 2020, 05:19
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.