Quote:
Originally Posted by ownedbycats
Also, another Action Chains issue:
I have a composite column, #chapters, which pulls from integer #chaptercount and provides formatted output. One of the outputs is "Not Set" if I haven't set a #chaptercount.
I have an action in one of my chains that checks the #chapters column to see if there's unread chapter and then changes the #percentread from 100 => 98 if so.
If it matters, technically #chapters is set to sort by text.
Code:
program:
f = re($#chapters, '(.*)/.*', '\1');
s = re($#chapters, '.*/(.*)', '\1');
if and(
$$#fanficcat,
check_yes_no('#onkobo', '', 1, 1),
$$#percentread ==#100,
(s - f) ==# 1
)
then '98'
else $$#percentread
fi
This fails with "not set" books. Template tester says could not convert string to float: 'Not Set' Which then breaks the chain when running on books with unset chaptercounts.
I tried adding a $#chapters != 'Not Set', to the checks, but that didn't work. Any idea what I missed?
|
As a said before, you could profit from a course in computer science.
What you are seeing is the difference between evaluation of parameters for a function and shortcutting for operators. For a function, all of the parameters are evaluated then passed to the function, in this case 'and()'. Because they are all evaluated the test
$#chapters != 'Not Set', doesn't stop evaluation of the other parameters.
However, if using shortcutting then evaluation stops once the result cannot change. For example
Code:
if '' && 2 * 3 then
will not evaluate the expression 2 * 3 because the clause (False && anything) will be False no matter the value of 'anything'.
Using shortcutting we can fix your condition in one of two ways:
Code:
if $#chapters != 'Not Set' &&
and(
$$#fanficcat,
check_yes_no('#onkobo', '', 1, 1),
$$#percentread ==#100,
(s - f) ==# 1
)
then ...
or as I would prefer for performance reasons
Code:
if $#chapters != 'Not Set' &&
$$#fanficcat &&
check_yes_no('#onkobo', '', 1, 1) &&
$$#percentread ==#100 &&
(s - f) ==# 1
then ...
Why performance? With shortcutting the evaluation of the conditions stops if a condition is False. With parameters all the conditions are evaluated no matter if one of them is False. Note that this argues that the most common False condition should come earlier in the && list.