PDA

View Full Version : Should not results handlers be where results are applied?



SilentRuin
June 20th, 2020, 15:59
Why is 5E/campaign/scripts/char_weapons.lua have function onAttackAction writing to the DB for ammo updates? I can't jump in and get a crack at it because its not a global script.

If that DB write was actually in the results handler, or even a global script, that would make so much more sense.

And also be full filling a need of mine by respecting the boundaries of what function applies the results of a roll.

I mention this for future consideration. If this is something that will actually be considered and be happening soon - let me know. Otherwise, I will proceed down a more painful path trying to work around this.

[I have worked around this - but it was 138 lines of code verses 20 if this was someplace else.]

Trenloe
June 20th, 2020, 17:47
The code is there because it is called from a specific window in the GUI and it directly accesses "stuff" in the GUI. It's arguable that it could be possible to write a stub in that file and call something in some other file (adding a layer of complexity there), but it is attached to a GUI window and that is where the code is.

You can override code in that file similar to the way you can override code in a Global script package. See some information here: https://www.fantasygrounds.com/forums/showthread.php?58755-ct_entry-lua&p=516228&viewfull=1#post516228 Depending on what you're doing you may not need to do all of the if super... code for the other functions. Try it first with only overriding the function you're using.

LordEntrails
June 20th, 2020, 17:55
MOD: moved to workshop forum.

SilentRuin
June 20th, 2020, 18:11
The code is there because it is called from a specific window in the GUI and it directly accesses "stuff" in the GUI. It's arguable that it could be possible to write a stub in that file and call something in some other file (adding a layer of complexity there), but it is attached to a GUI window and that is where the code is.

You can override code in that file similar to the way you can override code in a Global script package. See some information here: https://www.fantasygrounds.com/forums/showthread.php?58755-ct_entry-lua&p=516228&viewfull=1#post516228 Depending on what you're doing you may not need to do all of the if super... code for the other functions. Try it first with only overriding the function you're using.

As I said - I worked around it. And yes, by finding every call in 5E/campaign/record_char_weapons.xml and replacing it so I could do the exact same thing except with my logic in front of it. Yes, its a GUI but its also an untouchable update to the DB where you can't build anything on it after because you don't know if it changed or not.

In the end, my issue was worked around. I just didn't like a non accessible routine updating a DB entry in a way where you did not know if it updated or not. I just like minimal footprints in the main code in my stuff, but I had to resort to the heavy boots stomping through it.