Bug in QDK Pro 4.03 plus workaround
wsquires
13 May 2008, 14:42Where can I file a bug report? Here's the situation:
Problem:
Nested comparisons 'lose' the statement order because QDK doesn't enforce its own use of '{','}' to enclose all statements within the "then" or "else" branch of conditionals.
Description:
When a comparison has both "then" and "else" conditions, you nest a conditional inside the "then" of another conditional, and there's only a single statement in each block, its "else" code ends up in the "else" code of its outermost conditional. Example:
if <player has an object: lamp> then
if <the flag 'is_lit' = true> then
Print "you already turned on the light!"
else
Set the flag 'is_lit' to true.
end if
else
Print "you don't have the light!"
end if
when you close the script editor window, and re-edit the script, the line "Set the flag 'is_lit' to true" will end up as part of the outermost else as: "Set the flag 'is_lit' to true else Print "you don't have the light!""
To replicate:
1) Start a new game (I called mine "bugtest.asl")
2) Create a new, blank room (it doesn't matter what you call it, it's just there so the player will have a place to start) and give it a simple description. "Closet - This is a dark closet." for example.
3) Create an item called "flashlight" in the room. Again, give the flashlight a simple description under the "look" verb. "flashlight - This is a nice, shiny flashlight."
4) Create a new verb for it, "turn on", and select the "run a script" radio button. Click on the "Edit..." button to create a new script for this.
5) Immediately, click the "Add Conditional" button (2nd from the left at the top.) Click on the "Add" button next to the "If:" pane.
6) Select the condition "player has an object", and "flashlight". Click OK.
7) Click the "Edit..." button near the "Else:" pane.
8) In the editfield, type "You don't have the flashlight!" Click OK.
9) Click the "Edit..." button near the "Then:" pane.
10) Again, immediately click on the "add conditional" button.
11) Select the condition "a flag is set". Click on the "NOT" checkbox. Under "Condition parameters" type in "is_lit" into the editfield where it says "Flag:". Click OK.
12) Click the "Edit..." button next to the "Else:" pane. Type into the editfield, "The flashlight is already on!" Click OK.
13) Click the "Edit..." button next to the "Then:" pane. Under "Variables" select "Set a flag on" and - in the right hand editfield, select "is_lit" from the popup menu, or just type it in. Click OK
14) You should now be at the script editor for the inner nested conditional. Click OK.
15) You should now be at the script editor for the outer conditional. Click OK.
16) You should now be back at the main screen where you just added the "turn on" verb. It should still be selected. Click the "Edit..." button again. Whoops! Look at the "Else:" pane! It now says:
Print "The flashlight is already on!" Else Print "You don't have the flashlight!"
Workaround:
Make sure every "Then:" or "Else:" block in a nested conditional has at least two statements; this'll force QDK to insert opening and closing curly braces so it won't get confused later. A single conditional by itself is not a problem, just when you nest them. It may also occur if you nest a Select Case in a conditional too, though I haven't encountered that yet.
Problem:
Nested comparisons 'lose' the statement order because QDK doesn't enforce its own use of '{','}' to enclose all statements within the "then" or "else" branch of conditionals.
Description:
When a comparison has both "then" and "else" conditions, you nest a conditional inside the "then" of another conditional, and there's only a single statement in each block, its "else" code ends up in the "else" code of its outermost conditional. Example:
if <player has an object: lamp> then
if <the flag 'is_lit' = true> then
Print "you already turned on the light!"
else
Set the flag 'is_lit' to true.
end if
else
Print "you don't have the light!"
end if
when you close the script editor window, and re-edit the script, the line "Set the flag 'is_lit' to true" will end up as part of the outermost else as: "Set the flag 'is_lit' to true else Print "you don't have the light!""
To replicate:
1) Start a new game (I called mine "bugtest.asl")
2) Create a new, blank room (it doesn't matter what you call it, it's just there so the player will have a place to start) and give it a simple description. "Closet - This is a dark closet." for example.
3) Create an item called "flashlight" in the room. Again, give the flashlight a simple description under the "look" verb. "flashlight - This is a nice, shiny flashlight."
4) Create a new verb for it, "turn on", and select the "run a script" radio button. Click on the "Edit..." button to create a new script for this.
5) Immediately, click the "Add Conditional" button (2nd from the left at the top.) Click on the "Add" button next to the "If:" pane.
6) Select the condition "player has an object", and "flashlight". Click OK.
7) Click the "Edit..." button near the "Else:" pane.
8) In the editfield, type "You don't have the flashlight!" Click OK.
9) Click the "Edit..." button near the "Then:" pane.
10) Again, immediately click on the "add conditional" button.
11) Select the condition "a flag is set". Click on the "NOT" checkbox. Under "Condition parameters" type in "is_lit" into the editfield where it says "Flag:". Click OK.
12) Click the "Edit..." button next to the "Else:" pane. Type into the editfield, "The flashlight is already on!" Click OK.
13) Click the "Edit..." button next to the "Then:" pane. Under "Variables" select "Set a flag on" and - in the right hand editfield, select "is_lit" from the popup menu, or just type it in. Click OK
14) You should now be at the script editor for the inner nested conditional. Click OK.
15) You should now be at the script editor for the outer conditional. Click OK.
16) You should now be back at the main screen where you just added the "turn on" verb. It should still be selected. Click the "Edit..." button again. Whoops! Look at the "Else:" pane! It now says:
Print "The flashlight is already on!" Else Print "You don't have the flashlight!"
Workaround:
Make sure every "Then:" or "Else:" block in a nested conditional has at least two statements; this'll force QDK to insert opening and closing curly braces so it won't get confused later. A single conditional by itself is not a problem, just when you nest them. It may also occur if you nest a Select Case in a conditional too, though I haven't encountered that yet.
Alex
13 May 2008, 16:41Excellent bug report - if only they were all this detailed! I've added it to the "to do" list for the next version.
wsquires
14 May 2008, 17:02Related to the previous bug report:
The following is not a workaround, though it should be:
If you edit the ASL file to put the '{' and '}' in yourself, QDK Pro will remove them - again - when you try to edit the script that has the previously mentioned problem (though you may not see it until after you've edited the script)! Again, I believe this is because the language specifications for the scripts make the open/close curly braces optional - rather than required - for cases where a block of script code in a conditional has only one statement. Although C/C++ have no problem with one-statement "if"s, QDK gets confused (see the previous bug report.)
Besides the copy/paste bug, this is probably the most aggravating problem of QDK Pro which is otherwise a fine product for making IF!
The following is not a workaround, though it should be:
If you edit the ASL file to put the '{' and '}' in yourself, QDK Pro will remove them - again - when you try to edit the script that has the previously mentioned problem (though you may not see it until after you've edited the script)! Again, I believe this is because the language specifications for the scripts make the open/close curly braces optional - rather than required - for cases where a block of script code in a conditional has only one statement. Although C/C++ have no problem with one-statement "if"s, QDK gets confused (see the previous bug report.)
Besides the copy/paste bug, this is probably the most aggravating problem of QDK Pro which is otherwise a fine product for making IF!