PDA

View Full Version : 5E - adding entries to rRoll (odd behavior)



TheoGeek
March 5th, 2023, 03:12
Hey all!

So, I'm trying to clean up my Improved Critical extension and update some things...partly as a coding exercise, and partly to consolidate things. Anyway, the extension creates wrappers around modDamage and onDamageRoll to modify the results of the roll and I'd like to add fields to rRoll.clauses and rRoll.aDice to make it easier for some updates I am playing around with.

Long story short, adding fields seems to work like you'd expect - I can do things like


rRoll.clauses[1].bIsSpecialCritClause = false

and it works fine..."bIsSpecialCritClause" is added and is carried all the way through the processing. However, through testing, I found that if the name of the field is less than 12 characters long, it doesn't add it. For example,


rRoll.clauses[1].bIsModified = false

does not add "bIsModified", but


rRoll.clauses[1].bIsModified1 = false

does.

This leads me to believe that maybe this isn't a reliable way to add fields to rRoll.

Is it? And if not, what is the preferred method?

Thanks a ton!
Jeff.

damned
March 5th, 2023, 08:06
In your case what is the [1] for?
I regularly add shorter than 12 char length values to rRoll
is it possible that bIsModified is reserved in someway or is used elsewhere and is interfering?

TheoGeek
March 6th, 2023, 23:35
Hey damned!

In the example above, bIsModified is not reserved or otherwise used as far as a "find in files" went. I could print it first to see if it's there though. :) The "[1]" was just trying things out to see if the retrieved data from the first clause was added like I wanted, but the "1" at the end of the bIsModified was what I needed to add to get it to remain into onDamageRoll from modDamage. Anything less than a 13 character name for that field resulted in it being there fine in modDamage but not even being there in onDamageRoll's rRoll.

Ultimately though I think I need to do something different because I really want to add tables instead of strings or single items and when rRoll "leaves" modDamage and "enters" onDamageRoll, any tables I add become empty.

Thanks!
Jeff.

damned
March 6th, 2023, 23:44
Im no expert but some things to consider:

When you roll multiple dice the results are stored in an array (I think) and the [1] indicates the first of those:

eg rolling 3d6
rRoll.aDice[1].result is the result of the first dice

rRoll tends to convert most things into strings so for example when I pass a number into rRoll.nAttackBonus it comes out the other side as a string.
Could something like this be messing with your results?

If you do a Debug.chat("rRoll: ", rRoll) before you pass on to the next script are you seeing what you expected there?

TheoGeek
March 7th, 2023, 00:11
When you roll multiple dice the results are stored in an array (I think) and the [1] indicates the first of those:

Yup, the damage clauses are stored that way as well. I'm iterating through the clauses and matching the dice results to them for later - basically I need to store the "original" roll and the "modified" roll for each dice and the properties of the clauses they belong to so I can back them out if necessary given the options. In the current version of my extension, that's all done in the "onDamage" function, but that requires a bunch of manipulation (modifying sDesc, calling encode and decode, etc) that I might be able to avoid if I modify the damage before the damage clauses are updated for output.


If you do a Debug.chat("rRoll: ", rRoll) before you pass on to the next script are you seeing what you expected there?

Yeah, everything is fine in modDamage, but when it gets to onDamageRoll, it's blank, unless it's a string when it leaves modDamage. If I make things strings, then everything works fine, including the odd "13 character name thing" that I don't remember seeing before, all the way from modDamage to being passed out of onDamage.

"Someone" might say "why don't you just clone and own manager_action_damage.lua because that would be way easier, and "someone" would not be wrong. :) But I did it the way I did (by writing wrappers around those functions and calling them either before or after I modify the rRoll structure to look like it would have looked if I had modified those core functions.

It's more work for me, but I've only had to update it like twice because of ruleset changes.

So a lot of this is just learning the best ways to interact with the rulesets and how things like rRoll flow through the process.

Thanks again, and any advice is always appreciated!
Jeff.

damned
March 7th, 2023, 00:13
Methinks you need some input from Moon Wizard or superteddy57

Moon Wizard
March 7th, 2023, 05:11
I believe that the damage clauses in 5E are "rebuilt" when needed from the textual information. (i.e. decodeDamageTypes/encodeDamageTypes), so information in these clauses would not be preserved through the system as it is built when needed. You'll have to store any information you want to track outside of the damage action "clauses".

Regards,
JPG

TheoGeek
March 7th, 2023, 19:11
Thanks Moon - that's my understanding too. I think it also tries to convert to strings as damned said so tables are lost as are booleans. Numbers convert fine and strings are retained. I'm going forward with using strings - that seems to be the most reliable method, unless, of course, you have a better solution. :)

Thanks!
Jeff.