Simple one...

Orangez
25 Apr 2013, 13:15
Newbie alert! ;)

I guess this will be a simple question for you guys, but I'm struggling for a while now searching the wiki and such:

I've created an lockable object and a key. This works nicely, when the player has both objects you can unlock the container with 'unlock container name'

However:

The player will type things as:

unlock box with key
use key on box
open box

etc. etc.

How do I insert these into my game so they will all 'alias' unlock box?

I'm sure I'm overlooking the obvious here, but any help would be greatly appreciated!

I'm having great fun with this btw. Alas I'm more a writer then a tech guy! ;)

homeeman
25 Apr 2013, 15:27
You can always add the same script to different verbs for your object. So, while the box already has internal code to open when the conditions are met, you can tell the 'use' verb and any other verbs you add to 'unlock object box' in the GUI commands. If you were confident enough (and the code was obvious enough, which is not always the case) you could reference the box's unlock code that it already has (Run an object's script attribute). Let me know if you're still unsure of anything!

Liam315
25 Apr 2013, 15:39
I'm relatively new to the program too so someone else might have some better ideas, but I've considered the same problem for my own game.

The second 2 are simple enough.
"Use key on box" could be done in the use/give tab on either the key or the box, then unlocking the box in the script.
"Open box" when you have the key is just a matter of ticking the second box under the Locking heading down the bottom of the container tab.

It's "unlock box with key" that's the trickier one. The issue as I understand it is that a verb can't be simultaneously assigned to an object both by itself (unlock box) and requiring an object (unlock door with key). I've tried fiddling with my game code to have both but with no success, it's well beyond my limited experience.

A simple workaround could involve creating other names under the object tab (box with key, box using key), but someone with more knowledge of the inner workings of quest might have a more elegant solution than this.

Orangez
25 Apr 2013, 16:59
Ok, I think I got what you guys mean. Thank you!

Another one:

Without 'taking' or 'get the box' an 'open box' gives me 'it is locked'.

I would like it to say something along the way of 'The box is still on the ground'.

When it's in the players inventory it should indeed say 'it is locked'

Any thoughts?

Sora574
25 Apr 2013, 21:48
If you're referring to the 'Look at' description, just change it from 'Text' to 'Run script' in the dropdown box.
Then, just add something like:
if: [player has object] (box)
then: Print message (It is locked.)
else: Print message (It's still on the ground.)

Orangez
25 Apr 2013, 22:08
Ah! Thanks. Learning a lot here! :D

sonic102
25 Apr 2013, 23:37
Liam315 wrote:I'm relatively new to the program too so someone else might have some better ideas, but I've considered the same problem for my own game.

The second 2 are simple enough.
"Use key on box" could be done in the use/give tab on either the key or the box, then unlocking the box in the script.
"Open box" when you have the key is just a matter of ticking the second box under the Locking heading down the bottom of the container tab.

It's "unlock box with key" that's the trickier one. The issue as I understand it is that a verb can't be simultaneously assigned to an object both by itself (unlock box) and requiring an object (unlock door with key). I've tried fiddling with my game code to have both but with no success, it's well beyond my limited experience.

A simple workaround could involve creating other names under the object tab (box with key, box using key), but someone with more knowledge of the inner workings of quest might have a more elegant solution than this.


Oh yes it can. Quest has an Infocom-quality-parser like every other IF development system.

Go to the type "defaultobject" (If you need to know how tell me) and click the yellow Copy button. Now make a new attribute "key" without quotes. Set the type to "object".

Make a command "unlock #object_unlock# with #object2#" without quotes. Set script to:

if [object_unlock.key = object 2]
Unlock object [object_unlock]
. Print "you unlock it"
else
print "wrong key"

Liam315
26 Apr 2013, 03:15
sonic102 wrote:Oh yes it can. Quest has an Infocom-quality-parser like every other IF development system.

Go to the type "defaultobject" (If you need to know how tell me) and click the yellow Copy button. Now make a new attribute "key" without quotes. Set the type to "object".

Make a command "unlock #object_unlock# with #object2#" without quotes. Set script to:

if [object_unlock.key = object 2]
Unlock object [object_unlock]
. Print "you unlock it"
else
print "wrong key"


Brilliant! That's a big help, thanks for that :) I knew it must have been possible somehow but there was no way I was getting that on my own.

EDIT: I ended up going about it a slightly different way, just as much an exercise in building custom commands than actually achieving the goal. Rather than edit the defaultobject type, I set the script to check if the object was lockable in the first place to give a different response if it wasn't. If it was, it then checks if the key is correct and runs any scripts accordingly. I've only tested it on one object so I'm not sure what happens if the object_unlock doesn't have an unlock message or onunlock script. If it does cause problems then I'm sure they could be solved by nesting each one in another IF script.

Command Pattern:
unlock #object_unlock# with #object2#; unlock #object_unlock# using #object2#

if (HasAttribute (object_unlock, "locked")) {
if (object_unlock.key = object2) {
set (object_unlock, "locked", False)
msg (object_unlock.unlockmessage)
do (object_unlock, "onunlock")
}
else {
msg (object2.article + " doesn't fit in the lock.")
}
}
else {
msg (object_unlock.article + " is not something that's locked in the first place.")
}

Orangez
26 Apr 2013, 07:30
Great forum. Love all the help!

---

I'm currently facing a situation where the player is entering a dark location.

I've created an object 'lightswitch' that can lighten the location on 'use' (or 'flip switch')

BUT for some reason the player can not exit the location (a toilet btw) without turning the light on.

So, if it's dark there is no exit visible. When it's light the east exit pops up.

I'm sure there is a setting somewhere? I'm using the web interface btw because I only own a mac and an ubuntu system.

Have a great weekend and thanks for all the help!

Liam315
26 Apr 2013, 09:05
If you select the exit (the one from the room that is dark), in the options tab there is a checkbox that says "object is a lightsource." Check the box and set the brightness to weak, that way the player can use it but it doesn't illuminate the whole room.

Orangez
27 Apr 2013, 08:15
Great! This rocks! :)

psymann
27 Apr 2013, 20:32
homeeman wrote:you could reference the box's unlock code that it already has (Run an object's script attribute).


Fantastic, that's just solved my similar problem today (that "use key on door" wasn't doing the same as "unlock door"), as I hadn't realised that's what "run an object's script attribute" meant :-)

That's saved me a goodly bit of time, thanks!

psy

psymann
18 May 2013, 23:41
sonic102 wrote:Go to the type "defaultobject" (If you need to know how tell me) and click the yellow Copy button. Now make a new attribute "key" without quotes. Set the type to "object".

Make a command "unlock #object_unlock# with #object2#" without quotes. Set script to:

if [object_unlock.key = object 2]
Unlock object [object_unlock]
. Print "you unlock it"
else
print "wrong key"


That's lovely, thanks, as I'd just been working on the same unlocking thing and not thought of anything so neat and tidy.

Some extras:

[list][*]I didn't even need to do any editing of the defaultobject since if I'd used the GUI to set the object to be locked, the attribute "key" was already added to that object.[/*:m]
[*]I found it better, rather than the [unlock object ; print "you unlock it"] bit, to run the object's script [do (objecttounlock, "unlock")] -- or "Run an object's script attribute" on the GUI -- which saved me typing in anything else.[/*:m]
[*]I enhanced the pattern to cope not only with "unlock #object_unlock# with #object2#" but also "use #object2# to unlock #object_unlock#". As a "regular expression" pattern, instead of a "command pattern" pattern, that came out as: (^unlock (?<object_unlock>.*) (with|using) (?<object2>.*)$|^use (?<object2>.*) to unlock (?<object_unlock>.*)$)[/*:m]
[*]And finally I added a different Fail message if the object_unlock actually had a "key" attribute, than if not, ie if it had a key attribute but the player had used the wrong key, it said wrong key, whereas if the object didn't have a key attribute, ie wasn't something that could be unlocked, then it said it couldn't be unlocked.[/*:m][/list:u]

That gave me:

Pattern: Regular expression
(^unlock (?<object_unlock>.*) (with|using) (?<object2>.*)$|^use (?<object2>.*) to unlock (?<object_unlock>.*)$)

Script:

if (object_unlock.key = object2) {
do (object_unlock, "unlock")
}
else {
if (HasAttribute(object_unlock, "key")) {
msg ("You can't use that as a key.")
}
else {
msg ("You can't unlock that.")
}
}


Which I think not only covers all the eventualities I could think of, but also works with all lockable objects in my whole game with hardly any code thanks to your neat solution ... until then it was sort of working but very inefficiently!

Thanks :-)

psy