Help needed for creating an unlockable container

I am trying to create a locked drawer with a spoon inside that can be put in inventory. The drawer can be unlocked and then opened by using a key found on the table in the same room. The drawer won't unlock.

My code:

<asl version="580">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="The Far Lands">
    <inherit name="theme_retro" />
    <gameid>56ba61e6-30ad-48a8-843f-8c3e668952da</gameid>
    <version>1.0</version>
    <firstpublished>2018</firstpublished>
    <author>Daniel Ratliff</author>
    <category>Fantasy</category>
    <allowlookdirections />
    <deactivatecommandlinks type="boolean">false</deactivatecommandlinks>
    <statusandcompassattop />
    <turnoffcompass type="boolean">false</turnoffcompass>
    <turnoffinventory type="boolean">false</turnoffinventory>
    <clearscreenonroomenter />
    <panestheme>Midnight</panestheme>
    <gridmap type="boolean">false</gridmap>
    <turnoffplacesandobjects type="boolean">false</turnoffplacesandobjects>
    <showpanes />
    <shadowbox type="boolean">false</shadowbox>
    <borderlesscursor type="boolean">false</borderlesscursor>
    <showborder type="boolean">false</showborder>
    <bordercolour>LightCyan</bordercolour>
    <autodescription />
    <attr name="autodescription_description" type="int">2</attr>
    <attr name="autodescription_youcansee" type="int">3</attr>
    <attr name="autodescription_youcango" type="int">4</attr>
    <autodescription_youarein_newline />
    <autodescription_youcansee_newline />
    <autodescription_youcango_newline />
    <autodescription_description_newline />
    <attr name="changeroom_newline" type="boolean">false</attr>
    <showcommandbar />
    <subtitle>Demo</subtitle>
    <cover>Game Cover.png</cover>
    <description><![CDATA[Welcome to <b>"The Far Lands-Part 1"</b> great adventurer. Here you will explore the heights and depths of a great forgotten world full of intrigue, adventure, and mystery! If you can make your way through the puzzling landscapes and magical cities, outwit enemies and befriend friends, you will obtain the holy grail of adventuring! Exciting exploration awaits!]]></description>
  </game>
  <object name="Shack Yard">
    <inherit name="editor_room" />
    <isroom />
    <description>You are on a nice green yard.</description>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
      <drop type="boolean">false</drop>
    </object>
    <object name="Mailbox">
      <inherit name="editor_object" />
      <inherit name="container_closed" />
      <feature_container />
      <hidechildren />
      <listchildren />
      <listchildrenprefix>It contains</listchildrenprefix>
      <isopen type="boolean">false</isopen>
      <close type="boolean">false</close>
      <drop type="boolean">false</drop>
      <usestandardverblist type="boolean">false</usestandardverblist>
      <inventoryverbs type="stringlist">
        <value>Look at</value>
        <value>Use</value>
        <value>Drop</value>
        <value>Open</value>
        <value>Close</value>
      </inventoryverbs>
      <useindividualverblist type="boolean">false</useindividualverblist>
      <look>You got Mail!!!</look>
      <onclose type="script">
      </onclose>
      <onopen type="script">
      </onopen>
      <object name="Letter">
        <inherit name="editor_object" />
        <look><![CDATA[Welcome to <b>"The Far Lands-Part 1"</b> great adventurer. Here you will explore the heights and depths of a great forgotten world full of intrigue, adventure, and mystery! If you can make your way through the puzzling landscapes and magical cities, outwit enemies and befriend friends, you will obtain the holy grail of adventuring! Exciting exploration awaits!]]></look>
        <take />
        <drop type="boolean">false</drop>
        <ontake type="script">
          msg ("The mailbox is empty.")
        </ontake>
      </object>
    </object>
    <exit alias="in" to="Shack">
      <inherit name="indirection" />
    </exit>
  </object>
  <object name="Shack">
    <inherit name="editor_room" />
    <description>You are inside a sparsely decorated shack. You can see a staircase in a corner.</description>
    <enter type="script">
    </enter>
    <object name="Table">
      <inherit name="editor_object" />
      <inherit name="surface" />
      <look>This is a rather plain table!</look>
      <feature_container />
      <hidechildren />
      <listchildren />
      <listchildrenprefix>It contains</listchildrenprefix>
      <drop type="boolean">false</drop>
      <object name="Candy">
        <inherit name="editor_object" />
        <inherit name="edible" />
        <look>It appears to be a nondescript piece of candy. I wonder what will happen if I eat it...</look>
        <take />
        <feature_edible />
        <eatmsg>Suddenly, a white rabbit wearing a waistcoat and sporting a pocket watch appears. "You shouldn't have eaten that he says," just beffore dashing off. Suddenly you feel all tingly... and belch.</eatmsg>
        <drop type="boolean">false</drop>
      </object>
      <object name="Key">
        <inherit name="editor_object" />
        <look>It is a nondescript key.</look>
        <drop type="boolean">false</drop>
        <take />
        <feature_usegive />
        <selfuseon type="scriptdictionary">
          <item key="Drawer">
            HelperOpenObject (Drawer)
          </item>
        </selfuseon>
      </object>
    </object>
    <exit alias="out" to="Shack Yard">
      <inherit name="outdirection" />
    </exit>
    <exit alias="up">
      <inherit name="updirection" />
      <scenery type="boolean">false</scenery>
      <locked type="boolean">false</locked>
    </exit>
    <object name="Drawer">
      <inherit name="editor_object" />
      <inherit name="openable" />
      <inherit name="container_lockable" />
      <look>Do drawers wear drawers?</look>
      <drop type="boolean">false</drop>
      <feature_container />
      <close type="boolean">false</close>
      <autounlock type="boolean">false</autounlock>
      <autoopen type="boolean">false</autoopen>
      <keycount type="int">1</keycount>
      <key type="object">Key</key>
      <object name="Spoon">
        <inherit name="editor_object" />
        <attr name="feature_usegive" type="boolean">false</attr>
        <look>It is the "missing" spoon!</look>
        <drop type="boolean">false</drop>
        <take />
        <ontake type="script">
          msg ("There is no spoon!")
        </ontake>
      </object>
    </object>
  </object>
</asl>

If the player enters "unlock drawer", I would expect that to work.

If the player enters "open drawer", it should complain that it's locked, because the player needs to specifically unlock the drawer before they try to open it.

If the player enters "use key on drawer", it runs the function HelperOpenObject (Drawer), which is exactly the same as the player typing "open drawer".

If you want "open drawer" to unlock it if the player has the key, go to the drawer's 'container' tab and tick the box "Automatically unlock if player has the key(s)".

If you want "use key on drawer" to unlock the drawer, rather than just trying to open it, you could change its script to either do (object, "unlock") or object.locked = false.


mrangl, this does open the drawer via text command, but not by text links,. Also the spoon is not showing up in the text once the drawer is unlocked (I do not plan on uploading the game with the inventory and room object sidebars.


There should be no difference between clicking links and typing in the command.

Which link in particular doesn't work? Is it unlocking the drawer you have a problem with, or opening it? And what does it say when you try?

If you want the contents to be listed in the main text when the drawer is opened, you need to tick the box "List children when object is looked at or opened" on the container tab.


Unlocking the drawer. It says the drawer is locked even when the key is in the inventory. I have the automatically unlock checkbox marked on the drawer pointing to the key. I have also checked what you suggested, but I have to look at the drawer after unlocking it for the text to appear.


Unlocking the drawer. It says the drawer is locked

Unlocking the drawer should never tell you that it's locked.

Are you, as the player, clicking on the drawer and choosing the "Unlock" button or menu item?

If you have the key, it will say "Unlocked."
If you don't, it will say "You do not have the key."

Or are you clicking "Open"?

This will tell you "It is locked."

The player needs to unlock the drawer, and then open it. Two actions.

Or are you clicking "use" on the key?

As I said in my first reply, "use key on drawer" is the same as "open drawer" - it won't work unless the player unlocks the drawer first in the code you gave.


There is no "unlock" option when I click the word drawer, with or without the key. I have the drawer labeled as a "Closed Container" type.


OK.

On the Drawer object, go to the 'Object' tab.
At the bottom, there should be a list marked "Display verbs". It is above the "Inventory verbs" list.

In the Display verbs list, add a new verb "Unlock". You can add "Lock" as well if you want.

It looks like you might have the option "Automatically generate object display verbs list" turned off, which means that when you create a locked container you will need to manually add Unlock to the menu.


It works perfectly now. Thanks!


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

Support

Forums