Varsuuk
March 14th, 2019, 00:13
[SOLVED]
First off, if DB.addHandler in a lua script associated with a windowless is best way, I will be happy as it puts it all in one place.
But I was wondering because I have seen calls to addHandler that took a wildcard expanded list of args so that the handler routine basically call "update your data" on all the "related" fields - whether they need updating or not if any of their, let's say 6 ;) "trigger" fields are updated.
I thought perhaps to just register a handler for the changing of a mod value on each of the 6 attires separately. But I wondered if there is a scaling issue and if one might cause poor performance by having many handlers when can do with less at the cost of "waster work" when called.
The initial way I did it before I realized handlers could be neater was to have the trigger control have this script field:
<anchored to="label_strength" />
<script>
function onValueChanged()
window.adjusted_str_score.updateValue();
end
</script>
And the recipient field (in same sheetdata are) have:
<script>
function onInit()
updateValue();
end
function updateValue()
setValue(window.strength_base.getValue() + window.str_base_manual_mod.getValue());
end
</script>
This works, as I type in the manual modifications field, the total of auto and manual mods updates in real time. None of the other attributes ones do, of course
But basically the same code is spread out among all 6 except for the control names being changed to protect the guilty. (bad Dragnet reference, carry on...)
1. Which would folks suggest is "better" more "elegant"?
2. Is there a reason to be careful of adding too many such handlers via DB.addHandler() individually vs grouping them?
Thanks folks!
(I'm glad that a lot of my questions now are about which way or is it safe/efficient to do it this way vs "I can't get this to work, how do I do it" - between my better understanding in being able to read existing rulesets and the wonderful* API page - I've been able to get what I need done each time if not the fastest when it is UI and when I typo restext instead of textres in half the controls and don't notice it - but I digress)
* = I REALLY would love a way to search on a function name and it return all API entries where it exist though, faster than my current check "reasonable" guesses then rest ;)
First off, if DB.addHandler in a lua script associated with a windowless is best way, I will be happy as it puts it all in one place.
But I was wondering because I have seen calls to addHandler that took a wildcard expanded list of args so that the handler routine basically call "update your data" on all the "related" fields - whether they need updating or not if any of their, let's say 6 ;) "trigger" fields are updated.
I thought perhaps to just register a handler for the changing of a mod value on each of the 6 attires separately. But I wondered if there is a scaling issue and if one might cause poor performance by having many handlers when can do with less at the cost of "waster work" when called.
The initial way I did it before I realized handlers could be neater was to have the trigger control have this script field:
<anchored to="label_strength" />
<script>
function onValueChanged()
window.adjusted_str_score.updateValue();
end
</script>
And the recipient field (in same sheetdata are) have:
<script>
function onInit()
updateValue();
end
function updateValue()
setValue(window.strength_base.getValue() + window.str_base_manual_mod.getValue());
end
</script>
This works, as I type in the manual modifications field, the total of auto and manual mods updates in real time. None of the other attributes ones do, of course
But basically the same code is spread out among all 6 except for the control names being changed to protect the guilty. (bad Dragnet reference, carry on...)
1. Which would folks suggest is "better" more "elegant"?
2. Is there a reason to be careful of adding too many such handlers via DB.addHandler() individually vs grouping them?
Thanks folks!
(I'm glad that a lot of my questions now are about which way or is it safe/efficient to do it this way vs "I can't get this to work, how do I do it" - between my better understanding in being able to read existing rulesets and the wonderful* API page - I've been able to get what I need done each time if not the fastest when it is UI and when I typo restext instead of textres in half the controls and don't notice it - but I digress)
* = I REALLY would love a way to search on a function name and it return all API entries where it exist though, faster than my current check "reasonable" guesses then rest ;)