About asking a question before entering a room

agnes
05 Jan 2016, 13:48
I want to lock the exit to a room, if the player could give a correct answer about a question, he could enter the room.
How can I make it :?:

OurJud
05 Jan 2016, 14:28
This is the script for a very simplified COMMAND with NAME UseKeyPad (You may call it whatever you want; Password, Locked... whatever)

Add a command for 'use keypad' to the room where the keypad is used, and give it the name UseKeyPad.

msg ("Enter password")
get input {
if (result="123456") {
MoveObject (player, Hallway)
}
else {
msg ("Incorrect password.")
do (UseKeyPad, "script")
}
}


password.jpg


Please bear in mind, that should a player get to this point without knowing the password, they'll be trapped in a loop with no escape... At least I believe so (not tested for that)

If this is the case, then simply give them a 'safe word' before using the keypad, and then add another 'if' rule:

if (result="exit") {
ShowRoomDescription
}

OurJud
05 Jan 2016, 14:52
Or alternatively, use the 'lock exit' function. (click on the exits tab of the room where you need the password, click on the exit you want to lock, clcik 'edit', then tick the box which says 'Locked'. You must also give this room a keyword (it will tell you where to add the keyword - I called mine 'locked')

Then go back to your room description, change it to 'Run a Script' from the dropdown menu, and make it look like this:

locked.jpg


If you would rather use code, click the icon second from the right (looks like a document), and add this:

msg ("There is a guard here. He asks you for the password. The locked door is north. East is an ungaurded exit.")
get input {
if (result="e") {
MoveObject (player, room 3)
}
else if (result="1234") {
UnlockExit (locked)
msg ("The gaurd steps aside to allow you access.")
}
else {
msg ("\"Wrong password.\"")
ShowRoomDescription
}
}


Remember to add extra if (result="e") { MoveObject (player, room 3) } for any other unlocked exits in the room.