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