Make Lua evaluate 0 to false and non 0 numbers to true

if you’re doing the string conversions (ie the parsing of one script language to another) then why not just “wrap” the output script using conversion functions of your own making?

input:  Kronqueste

old output:  storyVariables[“Kronqueste”]

new output:  tobool(storyVariables[“Kronqueste”])

local function tobool(v) if (type(v) == "number") then return (v~=0) end return (not not v) end

The problem is, the scripts use those variables very arbitrarily (they were originally done by various book authors, over a timeframe of almost 15 years and already ported form another platform and language once during this time, so it’s just lot’s of legacy data not always in an ideal format), i.e. it’s very possible that the same variable will sometimes be used as a boolean but in another expression as an integer in a calculation and in another one as a boolen but by comparing to 0.

I just started to port the original expression handling code - it’s not that bad, it’s just not as beautiful as pure Lua would be :slight_smile:

then as per others’ prior replies, and if it were me, i’d require that all conditional expressions be explicit, ie add the “~=0”, then if used as numeric expression will still work.  (otherwise no bullet-proof way to trap all possible uses, as you’ve seen and know)