View Single Post
Old 03-24-2021, 04:37 AM   #4
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,489
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
On this topic:

Code:
program:
	if raw_field('#percentread') ==# '0' then '1'
	else raw_field('#percentread')
	fi
Running this on a book with #percentread undefined returns result as 1.What is the proper way to make it remain undefined?

I changed it to raw_field('#percentread', '1') and it remained undefined but that felt kludge. Empty string '' returned a 1 not sure why.
Here is what I would do.
Code:
program:
	v = raw_field('#myint', '');
	if !v then
		''
	elif v ==# 0 then
		'1'
	else
		 v
	fi
This is the same thing but not using the second parameter of raw_field.
Code:
program:
	v = raw_field('#myint');
	if v == 'none' then
		''
	elif v ==# 0 then
		'1'
	else
		 v
	fi
chaley is offline   Reply With Quote