From 762ebd59dfc22fd7e3078425b8af3b08afed61ba Mon Sep 17 00:00:00 2001 From: Roland van Laar Date: Fri, 24 Nov 2023 22:46:13 +0100 Subject: [PATCH] DIRECTOR: LINGO: improve lingo c_not It's a bit unexpected, but `not` works differently then the inverse of `if`. After testing in D4.0.4 the following two statements are true: defined variables are falsy when checked with not i.e. not varundefined => true and not vardefined => false only a var with value 0 is seen as false when checked with not i.e. not 0 => true --- engines/director/lingo/lingo-code.cpp | 8 +++++++- engines/director/lingo/tests/if.lingo | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) 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