want to know how to detect if exit is locked

caberg
17 Jun 2014, 02:55
i'm about creating my first game using quest and i got problem about detecting wether the exit (in this case have name roomunlock) is locked or unlocked.

here's the code:

if (HasAttribute(roomunlock, "locked")) {
UnlockExit (roomunlock)
msg ("you open the room")
}
else {
LockExit (roomunlock)
msg ("you lock the room")
}


with that code, i keep have message "you lock the room" again and again .... what is the valid code for detect exit locked or not ?

sorry about my bad english, not my mother language ... and i'll appreciate any kind of help from you guys.

Pertex
17 Jun 2014, 09:41
HasAttribute only checks if this attribute exists and the locked attribute always exists with an lockable exit. You have to check if this attibute is true or false, something like this:

if (HasAttribute(roomunlock, "locked")) {
if (roomunlock.locked) {
UnlockExit (roomunlock)
msg ("you open the room")
}
else {
LockExit (roomunlock)
msg ("you lock the room")
}
}

caberg
17 Jun 2014, 09:49
woaa that's code is works, thx Pertex. you're my life saver.

spend 2 days to discover it lol

jaynabonne
17 Jun 2014, 11:12
You could also just change the HasAttribute to GetBoolean in the original code. :)