diff --git a/hank/HInterface.hx b/hank/HInterface.hx index c1afa69..1fe3fe6 100644 --- a/hank/HInterface.hx +++ b/hank/HInterface.hx @@ -157,26 +157,16 @@ class HInterface { var node:StoryNode = cast(v, StoryNode); return viewCounts[node] > 0; } - switch (Type.typeof(v)) { - case TBool: - return v; - case TInt | TFloat: - return v > 0; - // TODO I would love to do away with this hack, but C++ type coercion turns random things into strings. This workaround fixes a specific bug - default: - if (Std.is(v, String)) { - var val = cast(v, String); - switch (val) { - case "true": - return true; - case "false": - return false; - default: - throw '$v: ${Type.typeof(v)} cannot be coerced to a boolean'; - } - } else - throw '$v: ${Type.typeof(v)} cannot be coerced to a boolean'; + if (Std.isOfType(v, Bool)) { + return v; + } else if (Std.isOfType(v, Int) || Std.isOfType(v, Float)) { + return v > 0; + } else if (Std.isOfType(v, String)) { + if (v == "false") return false; + else return v.length > 0; } + throw '$v cannot be coerced to a boolean'; + return false; } public function addVariable(identifier:String, value:Dynamic) {