PDA

View Full Version : How to get change event in a different node on DB



Xarxus
December 17th, 2022, 15:36
This time I have a problem that I don't know if it's fixable.

I have a list of skills with the window that manages them, everything works fine. Then I have another window
where I manage skill groups. In this one I have a windowlist that allows me to add or remove skills from the
group. Here, too, everything works fine.

In the first window, those of the skills, I added a windowlist that allows me to see which groups the skill is in.
A function when loading (or when refreshing the window) scrolls the groups adding those in which the skill is
present. This works well too.

The problem I want to solve consists in real-time updating of the list in the skill window, i.e. I would like to see
the group list updated if I have the single skill window open and add this to one or more groups or remove it
from these.

Is there any way to do this? I should go and check if something has changed in a tag of the DB that is not
exactly that of the skill. Can I "register" to receive the change event of something within a different DB node?

Moon Wizard
December 17th, 2022, 19:30
You can register a change event.
DB.addHandler([node/path], "onUpdate", [callback_function]);

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

Regards,
JPG

Xarxus
December 17th, 2022, 20:31
That's what I was needing! Ty.

Will onUpdate catch everything inside the node? Also additions and/or deletions? Even the children?
Or do I need to implement onAdd and onDelete as well, maybe even in the child version?

Moon Wizard
December 17th, 2022, 22:14
No, “onUpdate” is only to capture value changes on data nodes (string, number, etc).

The onChildAdded, onChildUpdate, and onChildDeleted events are for direct child change tracking.

JPG

Xarxus
December 17th, 2022, 22:49
I've done some experimenting and it seems I can use onChildUpdate because it seems to be invoked even when adding or deleting items.
A thousand thanks @Moon