Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×

ChatSetAttr Null Handling Issue

Good morning! I'm really hoping someone can help me out here. I'm trying to use chatsetattr's execute functionality to use ternary (if) statements to select which attribute to use. The character sheet I'm using allows for 4 different ranged weapons to be entered and stores which one is selected and that number drives which range/ammo/to-hit/etc is used for subsequent rolls. While the sheet has a lot of amazing functionality, this is a system where reloading (and spells) usually take more than one turn and I'm trying to write my own macros to track those reload times and spell casting times. What I have now is: !setattr --charid @{target|character_id} --evaluate --ReloadTime|(%FKW_Aktiv%==1)?%FKWLadezeit1%:(%FKW_Aktiv%==2)?%FKWLadezeit2%:0 Since up to 4 pieces of equipment are allowed, I want to write a macro that will work no matter how many such weapons my players have. The ternary statements work nested thusly, but if I try to reference an attribute that doesn't exist, even if you never get to them before finding a valid response.
I found my answer in <a href="https://app.roll20.net/forum/post/2477580/defaulting-to-an-attributes-max-value-when-the-current-box-is-empty-has-something-changed" rel="nofollow">https://app.roll20.net/forum/post/2477580/defaulting-to-an-attributes-max-value-when-the-current-box-is-empty-has-something-changed</a> Once I identified that the core issue was that it treats any null reference as empty, I realized that the macro was unable to handle empty. By adding 0 to the result, I ensure that if it's empty, it returns as 0 for the logic of the ternary statement: !setattr --charid @{target|character_id} --evaluate --ReloadTime|(%FKW_Aktiv%==1)?(%FKWLadezeit1%+0):(%FKW_Aktiv%==2)?(%FKWLadezeit2%+0):(%FKW_Aktiv%==3)?(%FKWLadezeit3%+0):(%FKW_Aktiv%==4)?(%FKWLadezeit4%+0):0
1598295547
GiGs
Pro
Sheet Author
API Scripter
Well done. I didnt know chatsetattr accepted such constructs. Pretty neat.