Below is a simple example of a bug I introduced to my game. The ACTUAL error was buried much more deeply. Very much more deeply. Oh, yes.
The classroom is a room.
x is a number variable. x is 2.
y is a number variable. y is 1.
When play begins:
say "Demonstrating a schoolboy error.";
say "x is initially [x].";
if y > 0:
let x be 3;
say "x is changed to [x].";
say "What? x is [x] again, and I never touched it.".
The output is:
The solution is, of course, that I use Let x be 3 instead of Now x is 3, creating a local variable in the if block.
I was surprised that the compiler allowed me to name a temporary variable with the same name as a global one, but I won’t fall for it again!
Don’t I know it, after 40 years of writing and maintaining code! But in C, C++, Pascal, etc., you usually have to explicitly declare that you are redefining the name locally, otherwise they assume you mean the global name, whereas, here, the redefinition is implicit in the “Let” . Hey, I’m not complaining - I was glad I was able to figure it out!
I remember trouble-shooting a big piece of C software for a large company where a complicated structure was declared globally, but in one segment a structure with the same name, contents and purpose was defined (in a header file) with a different shape. That structure, applied to data defined by the global structure, revealed subtly different values. How we laughed when we found out… NOT!