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 .
Create a free account

Token bar shows 0, stores null value

If you enter 0 manually into a token bar value, scripts that call for that value will find a 0. If you subtracted from the value of a token bar and the result is 0, then scripts that call for that value will find nothing - even though it shows 0 on the token.
Forum Champion
Marketplace Creator
API Scripter
Hi The Bard! Interesting find. I'd like to pass this on, but is there an easily demonstrable case where the difference between zero and null causes an error?
Using the situation which lead to my discovery of this as an example: An ability reduces the effectiveness of the target's armor. The target's armor value is stored in bar1 of the token. Using ScriptCards, I created a macro which would reduce the armor value on the token automatically, but I do not want the armor value to drop below 0 since that would mess with the math for attacks negatively (subtracting a negative armor value from damage rolls should not happen).  So at first I tried having it check the resulting bar value and, if below 0, set it to 0. When that didn't seem to work, I tried having it compare the result of the ability against the current value of bar1, and have it apply the lesser of the two. When the target's armor value contains a null value, however, it cannot compare the result of the ability check against the bar1 value properly, and ends up applying the full amount of the ability check, causing the value to be reduced to below 0. In the screencap below, the top card shows what happens when the value is set to 0 manually, and the bottom card shows what happens when the token's bar1 value has been reduced/subtracted to reach a value of 0.  The "Report" output line I included for troubleshooting shows the result of the ability check, then the bar1 value - you can see in the bottom card that there is no value to report.

Edited 1658318254
David M.
API Scripter
Just guessing, but it sounds like you are using a scriptcard conditional to compare directly to the bar value that is supposed to contain the armor value. Instead, can you assign a roll variable the value, and use that roll variable in your conditional? If you assign a roll variable a blank value the scriptcard parser will assign it a zero. So (if my assumption is correct), instead of this hypothetical direct comparison approach:   --#sourcetoken|@{selected|token_id}   --?[*S:t-bar1_value] -lt [$someVal]|... Try this transitive approach:   --#sourcetoken|@{selected|token_id}   --=bar1|[*S:t-bar1_value]   --?[$bar1] -lt [$someVal]|...
Thank you!  This works to get around the problem.  I didn't realize that ScriptCards would parse a blank value as zero (only been using it for 2 days).