View Single Post
Old 12-20-2021, 10:08 AM   #234
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,476
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Is there any functional difference between

Code:
check_yes_no(field('#bool'), '', '', '1')
and

Code:
check_yes_no(field('#bool'), 0, 0, 1)
First, you have the first parameter to check_yes_no() wrong. It is the field name, not the field value. Example:
Code:
check_yes_no('#bool', '', '', '1')
If you use field('...') then almost certainly check_yes_no() will return what is specified for is_undefined. It might return something else if the value of the field is itself a field name. It is possible that this is what you want because you don't know the field name until execution. For example, this would work:
Code:
check_yes_no(strcat('#', 'bool'), '', '', '1')
To answer your question, there is in general no difference between 1 and '1'. The value gets converted back and forth as needed. However, '' and 0 are not the same. The first is the empty string and the second results in the string '0'.

But to make things a bit more confusing the check_yes_no() function checks if the parameter is a 1 (or '1'). Anything else is assumed to be 0. Because of this peculiarity the following three are equivalent:
Code:
check_yes_no('#mybool', 0, 0, 1)
check_yes_no('#mybool', '', '', 1)
check_yes_no('#mybool', 'mybad', 'ohno', '1')
You should not depend on peculiarities like this. Do what the manual says: use the numbers 0 and 1.
chaley is offline   Reply With Quote