Creating locked exits which need user input to unlock

ringo
Hi guys. I'm probably being a right nitwit here, but I've been trying to create a locket exit and I want the user to correctly answer a question to unlock the room.

I thought I had the right idea by checking the result of the input, but it seems that I can only use a boolean and not the code if(result="the correct answer").

The code I've tried to use unsuccessfully is:

LockExit (locked design studio)
msg ("What is the latest version of html?")
get input {
msg ("Your answer is " + result)
}
if (result="html5") {
UnlockExit (locked design studio)
}
else {
msg ("You're locked in the room")

jaynabonne
Your usage of "result" needs to be within the { } following the get input.

LockExit (locked design studio)
msg ("What is the latest version of html?")
get input {
msg ("Your answer is " + result)
if (result="html5") {
UnlockExit (locked design studio)
}
else {
msg ("You're locked in the room")
}
}


You have it outside the get input, which means "result" is not set. (Did it give you an error about "result" being unknown?)

ringo
jaynabonne wrote:Your usage of "result" needs to be within the { } following the get input.

LockExit (locked design studio)
msg ("What is the latest version of html?")
get input {
msg ("Your answer is " + result)
if (result="html5") {
UnlockExit (locked design studio)
}
else {
msg ("You're locked in the room")
}
}


You have it outside the get input, which means "result" is not set. (Did it give you an error about "result" being unknown?)

Brilliant, it now works.... to a degree. The code now reads:

get input {
msg ("What is the latest version of html?")
get input {
if (result="html5") {
MakeExitVisible (lockedlivingroom)
msg ("The door swings open")
UnlockExit (lockedlivingroom)
IncreaseScore (1)
}
else {
msg ("You're locked in the room")
LockExit (lockedlivingroom)
}
msg ("Your answer is " + result)
}
}
LockExit (lockedlivingroom)

The problem now is that the subsequent unlock living room door doesn't let me left click on it, although the original link above it does. This effectively means the door has to be unlocked twice. Then when the question is answered correctly, I can move south, but only via the compass. The south link doesn't appear, even though I've made it visible on answering the question correctly.

Many thanks for your help.

jaynabonne
Two things...

First, I'm not sure why you have a second "get input" wrapped around the code. You're basically reading a line of input and throwing it away. Perhaps there is a reason, but I can't think of one at the moment.

Which leads me to the second, which is that it would really help if you could post your game here. To be honest, I can't fathom what you're talking about with the problem you're having. For example, I don't know what "unlock living room door" is that you are referring to nor what the link above it that works looks like. (And I didn't know you needed to or even could right-click on things in Quest.) As far as the missing south link, are you referring to the exits list that shows up in the room description? Are you showing the room description again after you make the exit visible? Stuff like that...

If you could post it here, I'm sure it can be easily solved.

ringo
My, you're quick off the mark, I'd not had time to edit the 'right'click' before you replied.

The script now reads:

LockExit (lockedlivingroom)
msg ("What is the latest version of html?")
get input {
msg ("The door swings open")
if (result="html5") {
UnlockExit (lockedlivingroom)
MakeExitVisible (lockedlivingroom)
}
else {
msg ("You're locked in the room")
}
}


The game is here: http://textadventures.co.uk/games/view/ ... he-web-web

jaynabonne
First, the game you posted still has the double "get input" in it. When I click the "living room door" and select "unlock", it echoes "unlock living room door", and then enters your first get input. At this point, you can't click on the link because it's executing a "get input". After you input *something* into that input field (which it swallows), it gives you the HTML question. At that point, you still can't click on the link because it's still in a "get input". After you enter the answer, you can then click on the link and get the menu. I hope that's what you were referring to.

As far as the south link, once you're past answering the question and the door is unlocked, if you type "l", you'll see that it shows the south link as being available. There is nothing to automatically show the exits again. If you want to reshow the room description, you can call the function ShowRoomDescription after you unlock the exit and make it visible.

Silver
The answer will only be correct until html6 comes out; assuming you are actually using that question in the game.

jaynabonne
Silver wrote:The answer will only be correct until html6 comes out; assuming you are actually using that question in the game.


That's a different problem. Someone could easily answer "5" as well, which would be correct but rejected by the game. So now to "guess the verb" and "guess the noun" we can add "guess the right form of the answer". :)

The Pixie
Silver wrote:The answer will only be correct until html6 comes out; assuming you are actually using that question in the game.

A solution to that is to make it clear that the game is set in a specific year when 5 is the current version. In game the answer will always be right.

ringo
jaynabonne wrote:First, the game you posted still has the double "get input" in it. When I click the "living room door" and select "unlock", it echoes "unlock living room door", and then enters your first get input. At this point, you can't click on the link because it's executing a "get input". After you input *something* into that input field (which it swallows), it gives you the HTML question. At that point, you still can't click on the link because it's still in a "get input". After you enter the answer, you can then click on the link and get the menu. I hope that's what you were referring to.

As far as the south link, once you're past answering the question and the door is unlocked, if you type "l", you'll see that it shows the south link as being available. There is nothing to automatically show the exits again. If you want to reshow the room description, you can call the function ShowRoomDescription after you unlock the exit and make it visible.

Thanks everybody for your swift explanations. I've managed to get the get input working well, as well as the opening of doors and the direction link as a function. Could I push my luck and ask how I can convert answers to lowercase and to check the get input against a list of possible correct answers i.e 5, html 5, five?

I should probably amend things so that opening the door puts you into the room instead of just making the exit visible. It seems like an unnecessary step and could lead to confusion.

http://play.textadventures.co.uk/Play.a ... dqaavuqyuq

ringo
The Pixie wrote:

"Silver"

The answer will only be correct until html6 comes out; assuming you are actually using that question in the game.


A solution to that is to make it clear that the game is set in a specific year when 5 is the current version. In game the answer will always be right.


The game is going to be for my students, so the year will always be when I tell them to work through the adventure. The eventual idea is to get them to collect the hardware that they need in a pc for graphic and web design (recommended spec) and then the game will move on to collecting audience and purpose (colour and typography etc) items for a specific brief. Finally they will be typing in html code from the basic skeleton right up to a specific layout and again it should meet the design brief, so css will be involved too. I'll need a scoring system which allows higher scores for no hints and maybe extra health for completing tasks quickly.

I'd also like to expand it eventually so that maths and English questions/tasks are embedded puzzles, as well as equality and diversity. The ultimate aim is that because it is an adventure game, they will engage with it much better.

jaynabonne
To lowercase your result, use:

result = LCase(result)


To check for a list of possible answers, you can create a string list attribute on some object (wherever it makes sense: could be on the game object or could even be on the room in question) and put the answers there. Then in your code, instead of

if (result = "html5") {

you can do:

if (ListContains(game.htmlanswers, result)) {

(That's assuming you have a string list called "htmlanswers" on the "game" object. Adjust accordingly. :) )

ringo
jaynabonne wrote:To lowercase your result, use:

result = LCase(result)


To check for a list of possible answers, you can create a string list attribute on some object (wherever it makes sense: could be on the game object or could even be on the room in question) and put the answers there. Then in your code, instead of

if (result = "html5") {

you can do:

if (ListContains(game.htmlanswers, result)) {

(That's assuming you have a string list called "htmlanswers" on the "game" object. Adjust accordingly. :) )

Top man. I'll give it a blast


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums