Pretty Inventory (and Places and Objects) Lists

K.V.

This can be done online or offline


Desktop users can skip these steps and download the library.


Step 1

Enable the advanced scripts feature (if you haven't already done so).


Step 2

Add this to the "User Interface Initialisation" script in code view (under the 'Advanced Scripts' tab):

if (not game.timeelapsed = 0) {
  UpdateContentsInLists
}

Step 3

Add this to the start script in code view:

UpdateContentsInLists

Step 4

Create a turn script (the name doesn't matter, just be sure to ENABLE it). Put this for the script in code view:

UpdateContentsInLists

Step 5

Create a function named UpdateContentsInLists (no parameters nor return type), and put this for the script in code view:

foreach (o, ListExclude(ScopeVisible(),game.pov)) {
  if (not HasAttribute(o, "listalias")) {
    o.listalias = GetDisplayAlias(o)
  }
  o.listalias = Replace(o.listalias," ","")
  containers = ListExclude(ListParents(o), game.pov)
  containers = ListExclude(containers, ListParents(game.pov))
  foreach (c, containers) {
    o.listalias = "  " + o.listalias
  }
}

Step 6

Create a function named PrettyInventory (no parameters nor return type), and put this for the script in code view:

stuff = ScopeInventory()
list = ""
int = 0
foreach (o, stuff) {
  int = int + 1
  o.prettyalias = "  " + GetDisplayNameLink(o, "object")
  foreach (c, ListExclude(ListParents(o), game.pov)) {
    if (ListContains (stuff, c)) {
      o.prettyalias = "  " + o.prettyalias
    }
  }
  br = ""
  if (int > 1) {
    br = "<br/>"
  }
  list = list + br + o.prettyalias
}
msg ("You are carrying:")
msg (list)

Step 7

Create an INVENTORY command

1. Create a command named pretty_inventory_cmd.

2. Set the pattern to 'Regular Expression'.

3. Put this for the pattern: ^i$|^inv$|^inventory$

4. Put this for the script in code view:

list = FormatObjectList(Template("CarryingListHeader"), game.pov, Template("And"), ".")
if (list = "") {
  msg (Template("NotCarryingAnything"))
}
else {
  PrettyInventory
}

CONCERNING SCENERY

If a scenery object is inside of any object which is in the player's inventory, the scenery object WILL BE DISPLAYED in the inventory pane, but...

There is no reason to fool around with scenery objects in containers. If something is scenery, it shouldn't be in the player's inventory (or inside of anything in the player's inventory).

If we want to hide something until a certain event has taken place, we need to set visible to false.

If we want something to exist just in case the player tries to interact with it, we need to make it scenery. (Sidenote: Once something set as scenery is directly taken, its scenery attribute is set to false.)


Example Game

http://textadventures.co.uk/games/view/tc6_kfxsteafa-ecf7sqew/pretty-lists

<!--Saved by Quest 5.7.6606.27193-->
<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="Pretty Lists">
    <gameid>ced348c0-a06d-4c0f-b9d2-a99b6ba6a322</gameid>
    <version>1.0</version>
    <firstpublished>2018</firstpublished>
    <feature_advancedscripts />
    <start type="script">
      UpdateContentsInLists
      bowl.inventoryverbs = ListExclude(bowl.inventoryverbs, Split("Open;Close;Use", ";"))
    </start>
    <inituserinterface type="script">
      if (not game.timeelapsed = 0) {
        UpdateContentsInLists
      }
    </inituserinterface>
    <author>KV</author>
    <description><![CDATA[An example game with pretty lists.<br/><br/>Much thanks to mrangel and DavyB!]]></description>
  </game>
  <command name="pretty_inventory_cmd">
    <pattern type="string">^i$|^inv$|^inventory$</pattern>
    <script>
      list = FormatObjectList(Template("CarryingListHeader"), game.pov, Template("And"), ".")
      if (list = "") {
        msg (Template("NotCarryingAnything"))
      }
      else {
        PrettyInventory
      }
    </script>
  </command>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
    <object name="table">
      <inherit name="editor_object" />
      <inherit name="surface" />
      <feature_container />
      <listchildren />
      <listchildrenprefix>On it, you see</listchildrenprefix>
      <takemsg>It's too big to take.</takemsg>
      <look><![CDATA[An oak dining table.<br/>]]></look>
      <displayverbs type="stringlist">
        <value>Look at</value>
      </displayverbs>
      <object name="bowl">
        <inherit name="editor_object" />
        <inherit name="container_open" />
        <feature_container />
        <close type="boolean">false</close>
        <open type="boolean">false</open>
        <displayverbs type="stringlist">
          <value>Look at</value>
          <value>Take</value>
        </displayverbs>
        <take />
        <listchildren />
        <look><![CDATA[A plastic bowl.<br/>]]></look>
        <object name="apple">
          <inherit name="editor_object" />
          <inherit name="edible" />
          <take />
          <feature_edible />
          <visible type="boolean">false</visible>
          <look><![CDATA[A red apple.<br/>]]></look>
          <eat type="script"><![CDATA[
            if (HasString(this, "eatmsg")) {
              msg (this.eatmsg)
            }
            else {
              msg (DynamicTemplate("Eaten", this))
            }
            if (HasInt(game.pov, "health")) {
              game.pov.health = game.pov.health + this.eathealth
            }
            destroy (this.name)
            msg ("<h3>You have won!</h3>")
            finish
          ]]></eat>
        </object>
        <object name="orange">
          <inherit name="editor_object" />
          <inherit name="edible" />
          <take />
          <feature_edible />
          <look><![CDATA[A navel orange.<br/>]]></look>
          <eat type="script">
            if (HasString(this, "eatmsg")) {
              msg (this.eatmsg)
            }
            else {
              msg (DynamicTemplate("Eaten", this))
            }
            if (HasInt(game.pov, "health")) {
              game.pov.health = game.pov.health + this.eathealth
            }
            destroy (this.name)
            apple.visible = true
            if (ListContains(ScopeReachable(),bowl)) {
              msg ("By some strange (but much appreciated) coincidence, an apple has magically appeared in the bowl!")
            }
          </eat>
        </object>
      </object>
      <object name="lazy susan">
        <inherit name="editor_object" />
        <inherit name="surface" />
        <feature_container />
        <listchildren />
        <listchildrenprefix>On it, you see</listchildrenprefix>
        <look>A lazy susan.  You can spin it to move items around the table.  (Your grandparents used to have one.)</look>
        <spin>You spin it.</spin>
        <displayverbs type="stringlist">
          <value>Look at</value>
        </displayverbs>
        <takemsg>It {once:appears to be}{notfirst:is} attached to the table.</takemsg>
      </object>
      <object name="hat">
        <inherit name="editor_object" />
        <inherit name="wearable" />
        <take />
        <look><![CDATA[It's just like Indiana Jones's hat.<br/>]]></look>
        <feature_wearable />
      </object>
    </object>
    <object name="manpurse">
      <inherit name="editor_object" />
      <inherit name="container_open" />
      <inherit name="wearable" />
      <take />
      <feature_container />
      <feature_wearable />
      <alias>Man Purse</alias>
      <look><![CDATA[A leather satchel.<br/>]]></look>
      <listchildren />
      <alt type="stringlist">
        <value>satchel</value>
        <value>bag</value>
      </alt>
    </object>
  </object>
  <turnscript name="update_contents_in_lists_turnscript">
    <enabled />
    <script>
      UpdateContentsInLists
    </script>
  </turnscript>
  <verb>
    <property>spin</property>
    <pattern>spin</pattern>
    <defaultexpression>"You can't spin " + object.article + "."</defaultexpression>
  </verb>
  <function name="UpdateContentsInLists"><![CDATA[
    foreach (o, ListExclude(ScopeVisible(),game.pov)) {
      if (not HasAttribute(o, "listalias")) {
        o.listalias = GetDisplayAlias(o)
      }
      o.listalias = Replace(o.listalias,"&nbsp;","")
      containers = ListExclude(ListParents(o), game.pov)
      containers = ListExclude(containers, ListParents(game.pov))
      foreach (c, containers) {
        o.listalias = "&nbsp;&nbsp;" + o.listalias
      }
    }
  ]]></function>
  <function name="PrettyInventory"><![CDATA[
    stuff = ScopeInventory()
    list = ""
    int = 0
    foreach (o, stuff) {
      int = int + 1
      o.prettyalias = "&nbsp;&nbsp;" + GetDisplayNameLink(o, "object")
      foreach (c, ListExclude(ListParents(o), game.pov)) {
        if (ListContains (stuff, c)) {
          o.prettyalias = "&nbsp;&nbsp;" + o.prettyalias
        }
      }
      br = ""
      if (int > 1) {
        br = "<br/>"
      }
      list = list + br + o.prettyalias
    }
    msg ("You are carrying:")
    msg (list)
  ]]></function>
</asl>

K.V.

PrettyInventoryLib.zip


If something is scenery, it shouldn't be in the player's inventory (or inside of anything in the player's inventory).

I think there's a place for scenery in the inventory. A bag might contain scenery objects for its handle/strap/zipper/etc. Any parts mentioned in the description, in case the player wants to try looking closer at them. Or the handle on a fork. Or lint on a sweater.


K.V.

I think there's a place for scenery in the inventory. A bag might contain scenery objects for its handle/strap/zipper/etc. Any parts mentioned in the description, in case the player wants to try looking closer at them. Or the handle on a fork. Or lint on a sweater.

I agree!

I was just trying to explain it from Quest's perspective (or Alex's perspective, I guess).


Examine bag
It's a burlap sack with straps sewn onto it.
Examine strap
It is made of leather and sewn on with strong thread.
Examine thread
It is Talon Superlock Spun Polyester. A little strange given the medieval setting, wouldn't you say?
Remove thread
You do not have a Thread Ripping Tool.
Examine polyester
It is a synthetic resin in which the polymer units are linked by ester groups.
Examine polymer
You do not have Microscope.

"Damn, this the most detailed game ever!"


K.V.

That's funny stuff!

...and, sadly, I am guilty of this! Well, I only coded down to the thread...


K.V.

Updated the INVENTORY command to display object links in the above code.


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

Support

Forums