PDA

View Full Version : In LUA, how do you find all nodes with a given matching value?



SilentRuin
July 20th, 2020, 00:26
In other words, how do I find all the nodes in db.xml that contain a given string? For my purposes the node value is a full exact match.

I know findNode goes after matches to the node name - but how do you find matches for a value? String in this case.

I'm still confused what is valid in an XML XPATh search in FGU. Or what to call to get it applied.

Moon Wizard
July 20th, 2020, 02:12
That's a very expensive operation in any context. However, you would have to iterate over every value node in the database using Lua to compare if you wanted to do that. I wouldn't recommend doing it for the whole database, as it will be too intensive. When we use filters in the existing rulesets, we search over specific fields (filter fields for campaign lists; keyword fields for reference manual)

Regards,
JPG

SilentRuin
July 20th, 2020, 02:18
That's a very expensive operation in any context. However, you would have to iterate over every value node in the database using Lua to compare if you wanted to do that. I wouldn't recommend doing it for the whole database, as it will be too intensive. When we use filters in the existing rulesets, we search over specific fields (filter fields for campaign lists; keyword fields for reference manual)

Regards,
JPG

Ewwww.

No way. Guess I'll just hardcode the nodes I know about then. That's what I was afraid of but never hurts to ask in case there is "magic" to be found :)

For sure notepad++ can find them in a text search in a blink of an eye - but it's free of caring about any schema context.

SilentRuin
July 20th, 2020, 03:35
How expensive is it to watch for a specific change to a specific effect?

The combat tracker entry will have a (C) concentration effect on it - and when it is removed (by the concentration logic when something is hit and fails constitution saving throw) - I want to do something when that happens.

SilentRuin
July 20th, 2020, 04:02
Never mind - I've found and example of it I think...



DB.addHandler(DB.getPath(node, "effects"), "onChildDeleted", onEffectsUpdated);

celestian
July 20th, 2020, 05:50
How expensive is it to watch for a specific change to a specific effect?

It depends on how many effects each CT entry has (and how many CT nodes) and how many things end up iterating over them. I've ran into some situations recently where this has become a noticeable problem in various situations.

Remember, more than likely something else is also probably doing the same thing you are for other reasons.

SilentRuin
July 20th, 2020, 15:58
It depends on how many effects each CT entry has (and how many CT nodes) and how many things end up iterating over them. I've ran into some situations recently where this has become a noticeable problem in various situations.

Remember, more than likely something else is also probably doing the same thing you are for other reasons.

I could limit it to only what I need it for but I'm unsure how to handle the addHandler()/removeHanlder() part of it without an onInit()/onClose() guarantee.

Don't get me wrong - I can put the add/remove in at certain logic points when what I've got is activated/deactivated - but I don't trust it as its dependent on nobody "getting around it through bad stuff happending" and leaving a handler up or multiple of them defined.

Unless it's harmless to define the same handler twice? That is my only worry with not having it tied to onInit/onClose logic. If something can go wrong - it will - and I don't want some hole where i have 100 duplicate defined handlers crippling the system.