diff --git a/engines/director/lingo/lingo-code.cpp b/engines/director/lingo/lingo-code.cpp index fd18ab6c118..f657f4e710b 100644 --- a/engines/director/lingo/lingo-code.cpp +++ b/engines/director/lingo/lingo-code.cpp @@ -1226,9 +1226,15 @@ void LC::c_or() { } void LC::c_not() { + // Not returns true when a variable is undefined or is an int and is zero. + Datum res; Datum d = g_lingo->pop(); - Datum res(d.asInt() == 0 ? 1 : 0); + if ((d.type == INT && d.u.i == 0) || d.type == VOID) { + res = Datum(1); + } else { + res = Datum(0); + } g_lingo->push(res); } diff --git a/engines/director/lingo/tests/if.lingo b/engines/director/lingo/tests/if.lingo index 460e6dec14b..d10df061346 100644 --- a/engines/director/lingo/tests/if.lingo +++ b/engines/director/lingo/tests/if.lingo @@ -7,6 +7,23 @@ if x = 6 then put 2 set y = 4 +-- defined variables are falsy when checked with not +-- i.e. not varundefined => true +-- only a var with value 0 is seen as false when checked with not +-- i.e. not 0 => true +scummvmAssert(varundefined = 0) +scummvmAssert(not varundefined = 1) + +set a to 0 +scummvmAssert(not a = 1) +set a to 0.0 +scummvmAssert(not a = 0) +set a to "string" +scummvmAssert(not a = 0) +set parray to [#pt: 1, #ar: 0] +scummvmAssert(not parray = 0) +-- + repeat with x = 1 to 6 if x = 3 then put 30 else if x = 4 then put 40