From e945dafca39f76c3e37f70df9299c69ed95dbdec Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 24 Mar 2022 11:40:14 +0000 Subject: [PATCH] Props: add defaultValue to getInt|Double Value Simplify handling where the property value might be nil. --- Nasal/props.nas | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Nasal/props.nas b/Nasal/props.nas index 7578f4f11..f4b9966f1 100644 --- a/Nasal/props.nas +++ b/Nasal/props.nas @@ -58,12 +58,22 @@ var Node = { return !!val; }, - getIntValue : func { - return math.round(me.getValue()); + getIntValue : func (defaultValue = 0) { + var v = me.getValue(); + if (!v) { + return defaultValue; + } + + return math.round(v); }, - getDoubleValue : func { - return num(me.getValue()); + getDoubleValue : func (defaultValue = 0.0) { + var v = me.getValue(); + if (!v) { + return defaultValue; + } + + return num(v); }, remove : func {