Axe Software Forums
  Quest Developer Forum
  QDK Bug


Author Topic:   QDK Bug
Tyrant posted 24-06-2001 23:28 GMT     
I have noticed a little bug in QDK involving conditions within conditions...has this been addressed? I have tested this bug out, and it is indeed something to look out for if you haven't noticed already. I have put together a small example of this bug with QDK, as well as the outcome. Remember, this is only a little example demonstrating the bug, and has nothing to do with my games.

Ok, I made a room, and in that room you can type the command "use keys on door". In order to open the door, the game has to make sure you have a bronze key, a silver key, and a gold key in order to open it. So, when you type in the command, here's the actions that take place:

1.) If the player has bronze key
Then (Check Condition #2 below)
Else Print "You don't have bronze key!"

2.) If the player has silver key
Then (Check Condition #3 below)
Else Print "You don't have silver key!"

3.) If the player has gold key
Then Print "All 3 keys combine to open the door."
Else Print "You don't have gold key!"


As you can see, it's basically conditions inside conditions to check a bunch of things in QDK to verify if you can enter the door or not. However, when playing the game, I noticed something is really screwed up. When I go back to the "use keys on door" command and look inside it, I noticed the conditions have somehow mixed themselves into one another. Here is what it now looks like:

1.) If the player has bronze key
Then (Check Condition #2 below)
Else Print "You don't have silver key!"

2.) If the player has silver key
Then (Check Condition #3 below)
Else (This is now blank!)

3.) If the player has gold key
Then Print "All 3 keys combine to open the door."
Else Print "You don't have gold key!"


Notice how the Else statement of condition #2 jumped into the Else statement of condition #1, and now nothing is in that space in #2.

I also noticed that the cure to this bug involves using the NOT statement instead. Instead of checking if there's a bronze key, you should check if there is NOT a bronze key. THEN print "You don't have a bronze key!", and under ELSE you add the 2nd condition. I have the feeling that Alex has addressed this problem by adding the NOT statement (NOT was never there in previous QDK releases), but I am posting it just in case since I don't recall anyone saying anything about it. If this bug was already been addressed and cured by adding a NOT statement, then please ignore this post:-) It's just a warning to people that you could loose some things when you use a lot of conditions within conditions without using the NOT statement. When checking for various conditions myself, I did not use the NOT statement, and therefore lost some things.

Alex posted 25-06-2001 11:49 GMT          
Alright, I confess the whole nested ifs thing is a bit screwed in Quest 2.19/QDK 1.0x. There have been various problems which have been fixed in the past few minor releases but in its current form there is no completely unambiguous way of getting things to work right.

Never fear, all is sorted in Quest/QDK 3.0 - these support braces around nested ifs meaning everything is clear.

passerby posted 26-06-2001 17:36 GMT          
Yes, Tyrant, i've encountered the same thing, and Alex was right (of course), its because QDK doesn't put braces around the inner 'if'. So if you type:

if condition1 then
if condition2 then
action1
else
action2

this is converted into the asl statement:

if got <condition1> then if got <condition2> then do <action1> else do <action2>

Quest then rereads this statement as

if condition1 then
if condition2 then
action1
else
action2

not the same as what you intended. The solution i use is to edit the asl file in notepad, and insert the braces manually:

if got <condition1> then {if got <condition2> then do <action1> else do <action2>}

The NOT statement approach works because it puts the inner 'if' statement into the 'else' clause of the outer if.

Also this error will happen only when there is a single 'if' inside of another - if there is more than one statement inside the outer 'if', everything inside will be made part of a procedure, so this problem won't occur.

So there are three possible solutions:

1. Arrange the conditions so that the inner 'if's are part of the 'else' statement of the calling 'if'. This is why u use the NOT statement.

2. Edit the asl file and put the braces around each nested if manually. (Use notepad, not word!)

3. Make sure that no inner if is the only statement in its clause.