It turns out I was mistaken. The problem probably had nothing to do with the code being in the player object's before property. I tried replacing PreParse early one morning before I had to run off to class, and I'd thought that it had worked, but it really hadn't.
However, now I really
have found the solution! I noticed how Kent Tessman is always using local variables in his routines, including those that use the word[] array, such as the very code from
Down that I had been looking at. I was suspecting that Hugo was setting the word[] entries to the words I was trying to test for when it read the line:
Code: Select all
if word[1] = "turn" and word[2] = "on" and word[3] = "lights"
Examining the executed code in the Debugger, I noticed that the CustomError message was always displayed whenever PreParse made it to that condition, even if the condition was not true.
I added local variables in my replaced PreParse routine and set them to the specific dictionary words from the player's command:
Code: Select all
local 1st, 2nd, 3rd
1st = word[1]
2nd = word[2]
3rd = word[3]
And now the condition that was giving me so much trouble looks like this:
Code: Select all
if 1st = "turn" or "switch" and 2nd = "on" and 3rd = "light" or "lights" or "lightswitch" or "lamp"
I'm pretty sure that the Hugo Book has some examples of testing for a specific array entry (but probably not the word[] array), so I don't understand why I had to do this, but it works, so I'm done questioning.
It turns out I was mistaken. The problem probably had nothing to do with the code being in the player object's before property. I tried replacing PreParse early one morning before I had to run off to class, and I'd thought that it had worked, but it really hadn't.
However, now I really [i]have[/i] found the solution! I noticed how Kent Tessman is always using local variables in his routines, including those that use the word[] array, such as the very code from [i]Down[/i] that I had been looking at. I was suspecting that Hugo was setting the word[] entries to the words I was trying to test for when it read the line: [code]if word[1] = "turn" and word[2] = "on" and word[3] = "lights"[/code] Examining the executed code in the Debugger, I noticed that the CustomError message was always displayed whenever PreParse made it to that condition, even if the condition was not true.
I added local variables in my replaced PreParse routine and set them to the specific dictionary words from the player's command:
[code]local 1st, 2nd, 3rd
1st = word[1]
2nd = word[2]
3rd = word[3]
[/code]
And now the condition that was giving me so much trouble looks like this:
[code]if 1st = "turn" or "switch" and 2nd = "on" and 3rd = "light" or "lights" or "lightswitch" or "lamp"[/code]
I'm pretty sure that the Hugo Book has some examples of testing for a specific array entry (but probably not the word[] array), so I don't understand why I had to do this, but it works, so I'm done questioning.