View Single Post
Old 01-21-2022, 04:20 AM   #296
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,509
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
EDIT: Commenting out line four makes it return #percentread (expected result). Was it trying to do math even if there was nothing matching for f and s? I guess I need to fix the newpercent bit somehow or rearrange the template so that lines 2-4 run after the 'not set' check.
The re() function isn't doing what you think it does. If the regular expression in
Code:
s = re($#chapters, '.*/(.*)', '\1')
matches nothing then s is assigned the value of $#chapters. You need to account for what happens if the pattern doesn't match the value. One way to do it is to verify that there is a '/' in $#chapters before extracting the values and doing the computation.

Yes, it will try to do the math with the values in s and f no matter what those values are.

You can use the debugger and breakpoints to look at the values of the variables and expressions to better get a handle on what your template is doing.
chaley is offline   Reply With Quote