Nested If statment bug

rizean
24 Jun 2007, 02:26
I am doing the Tutorial and I'm on step 15. I wrote an If statement to account for: faucet not on, player doesnt have glass, and player not in same room as faucet.

My if statement

If "faucet" is in the current room and "faucet" has the property "on" and the player has "glass"

Then Print "You fill the glass with water."
Modify "glass"'s property: "full"

Else If the player has "glass"
--Then If "faucet" is in the current room
----Then If "faucet" has the property "not on"
------Then Print "You must turn the faucet on to fill the glass."
----Else Print "You can not fill the glass here."
--Else Print "You must pick up the glass to fill it."

However after putting that into quest using the interphase it comes out:

If the player has "glass" and "faucet" is in the current room and "faucet" has the property "on" Then {
Print "You fill the glass with water."
Modify "glass"'s property: "full" } Else If the player has "glass" Then If "faucet" is in the current room Then If "faucet" has the property "not on" Then Print "You must turn the faucet on first." Else Print "You can not fill the glass here." Else Print "You must pick up the glass to fill it."


Notice how the else and them statements get out of order.

Elexxorine
25 Jun 2007, 08:11
Arg, compound if's are murder in QDK. I think you want something like this:
if got <glass> then {
if here <faucet> then {
if property <faucet; on> then {
msg <You fill the glass with water.>
property <glass; full>
}
else msg <You need to turn the faucet on first.>
}
else msg <You can't fill your glass here.>
}
else msg <You don't have a glass to fill.>
Which is much nicer. You can either pop that in through notepad or I think there's an asl editor in QDK now, I dunno. Or you can put it in normally using this sturcture. Hope this helps. The trick is not to use 'and's but put an if instead an if... :D