Unlock box with key
peter edwards
23 Jan 2014, 12:09I'm writing a game in which I have a lockable box and a key. Using the "container page" I have made the box unlockable with the command "unlock box". So far, so good. If, however, the player types "unlock box with key" he gets the message "That won't work". How can I make this style of command work, in addition to the simpler "unlock box"? Any help gratefully received (but please keep it simple if possible!)

Pertex
23 Jan 2014, 15:20You can easily do this in the container tab:


peter edwards
23 Jan 2014, 19:11Thank you for your swift reply, Pertex. I do appreciate it, but actually that part was not a problem. It allows you to use the command "unlock box" and, if you have the key, the box will unlock with the appropriate message. What I need is to be able to have the player say "unlock box with key" and get the same response. I would like this to happen in addition to the "unlock box" command.

Pertex
24 Jan 2014, 09:14OK, I got it. Then you need a new command
<command name="unlockwith">
<pattern>unlock #text# with #text2#</pattern>
<script>
obj = GetObject(text)
key = GetObject(text2)
if (obj = null) {
msg (Template("UnresolvedObject") + " (" + text + ")")
}
else if (key = null) {
msg (Template("UnresolvedObject") + " (" + text2 + ")")
}
else if (HasAttribute (obj, "key")) {
if (obj.key=key) {
HandleSingleCommand ("unlock "+ text)
}
}
else {
msg(Template(NoKey))
}
</script>
</command>
peter edwards
24 Jan 2014, 10:59Many thanks again, Pertex. I'm completely inexperienced in programming in the code view, but will carefully compare your listing with other commands to try and find out how to use it. If you can give me any hints, I'd be grateful.

Pertex
24 Jan 2014, 11:47If you are working with the gui, you can do this:
1. Create a new command
2. Click on 'Code View'
3. Copy the following code above into the code view window as shown in the picture

1. Create a new command
2. Click on 'Code View'
3. Copy the following code above into the code view window as shown in the picture
obj = GetObject(text)
key = GetObject(text2)
if (obj = null) {
msg (Template("UnresolvedObject") + " (" + text + ")")
}
else if (key = null) {
msg (Template("UnresolvedObject") + " (" + text2 + ")")
}
else if (HasAttribute (obj, "key")) {
if (obj.key=key) {
HandleSingleCommand ("unlock "+ text)
}
}
else {
msg(Template(NoKey))
}

peter edwards
24 Jan 2014, 16:41Thanks, Pertex, I'm getting there! But not quite there yet! I have assumed the word text to be box, and text2 to be key. When I type unlock box with key, I get the following error message. I'm confident you know what I've done wrong!
Error running script: Error compiling expression 'GetObject(box)': FunctionCallElement: Could find not function 'GetObject(Element)'
Error running script: Error compiling expression 'GetObject(box)': FunctionCallElement: Could find not function 'GetObject(Element)'
peter edwards
24 Jan 2014, 22:13P.S.
Pertex, this is what the code looks like now.
obj = GetObject(box)
key = GetObject(key)
if (obj = null) {
msg (Template("UnresolvedObject") + " (" + box + ")")
}
else if (key = null) {
msg (Template("UnresolvedObject") + " (" + key + ")")
}
else if (HasAttribute (obj, "key")) {
if (obj.key=key) {
HandleSingleCommand ("unlock "+ box)
}
}
else {
msg (Template(NoKey))
}
Does this help?
Pertex, this is what the code looks like now.
obj = GetObject(box)
key = GetObject(key)
if (obj = null) {
msg (Template("UnresolvedObject") + " (" + box + ")")
}
else if (key = null) {
msg (Template("UnresolvedObject") + " (" + key + ")")
}
else if (HasAttribute (obj, "key")) {
if (obj.key=key) {
HandleSingleCommand ("unlock "+ box)
}
}
else {
msg (Template(NoKey))
}
Does this help?
george
24 Jan 2014, 22:23This might help, you don't need to substitute box and key for text and text2 in the code. Leave text and text2 as is. Quest knows that text and text2 become box and key once the command happens.
peter edwards
24 Jan 2014, 23:03Thank you, Pertex and George. It now works!