View Single Post
Old 04-05-2021, 06:59 AM   #25
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,495
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Should local variables work for check_yes_no?
No, not in the way you think. Because check_yes_no() needs the raw value it requires the name of the field, not the value of the field. Thus this will work
Code:
program:
	f = '#mybool';
	check_yes_no(f, 1, 1, 1)
but this will not. The value is always considered to be undefined.
Code:
program:
	f = $#mybool;
	check_yes_no(f, 1, 1, 1)
If you want to use a local variable containing a value then you must do something like this:
Code:
program:
# must use raw_field()
	f = $$#mybool;
# A bool column fetched with raw_field will have 1 of 3 values, True, False, or None
	if f == 'true' then
		'yes'
	elif f == 'false' then
		'no'
	elif f == 'none' then
		'undefined'
	else
		'what?'
	fi
Another way of saying the above is
Code:
program:
# must use raw_field()
	f = $$#mybool;
	first_non_empty(
		test(f == 'true', 'yes', ''),
		test(f == 'false', 'no', ''),
		test(f == 'none', 'undefined', '')
	)
chaley is offline   Reply With Quote