The Places and Objects pane

I decided long ago to have the items in the places and objects pane and inventory pane be capitalized. Now, I found that when I sell an item to a shop, which shows in the objects pane, it is in lower case and if I buy it back it is still in lower case.
I can't add the CapsFirst function to it because many items have two words in the name.

In this custom sell command, how can I get the desired effect I need?

if (not HasAttribute(game.pov.parent, "stock")) {
  ClearTurn
  msg ("You can't sell stuff here.")
}
else if (not object.parent = game.pov) {
  ClearTurn
  msg ("You're not carrying " + object.article + ".")
}
else if (HasAttribute(object, "burned")) {
  if (object.burned = true) {
    ClearTurn
    msg (player.parent.owner.alias + " says,<br><i>I have no use for a used torch.")
  }
}
else if (HasAttribute(object, "sell")) {
  ClearTurn
  game.selling_object = object
  Ask ("I will give you " + game.selling_object.price + " gold. OK?") {
    object = game.selling_object
    if (result) {
      msg ("You sell " + object.article + " for " + object.price + " gold.")
      game.pov.money = game.pov.money + object.price
      if (GetBoolean(object, "cloneme")) {
        RemoveObject (object)
      }
      else {
        object.parent = game.pov.parent.stock
        SetUpMerchandise (object)
      }
    }
    else {
      msg ("You turn down the offer of " + object.price + " gold.")
    }
  }
}

Actually, I think it needs to be done in the SetUpMerchandise function.

if (not HasString(obj, "alias")) {
  obj.alias = obj.name
}
obj.listalias = obj.alias + " (" + DisplayMoney(BuyingPrice(obj)) + ")"
obj.cloneme = false
obj.take => {
  StealObject (this)
}
obj.buy => {
  BuyObject (this)
}

I was going to ask.

So, am I right in assuming that the alias is lowercase, but the listalias has capitals?

In that case, I'd suggest replacing
obj.listalias = obj.alias + " (" + DisplayMoney(BuyingPrice(obj)) + ")"
with something like:

listalias = ""
foreach (word, Split (GetDisplayAlias (obj), " ")) {
  listalias = listalias + " " + CapFirst (word)
}
obj.listalias = Mid (listalias, 2) + " (" + DisplayMoney(BuyingPrice(obj)) + ")"

This is one place I really wish Quest had a regexp replace function. Doing the same thing in JS would be as simple as:

object.listalias = object.alias.replace (/\d\w/g, letter => letter.toUpperCase());

I notice that this function adds the price to the object's listalias… you'll probably need to do the same (in BuyObject?) when the price is removed.


This worked for the buy command. I had added an attribute called orignalalias to sellable objects which returns listalias back.

if (object.price > game.pov.money) {
  msg ("You can't afford that!")
}
else {
  object.take = true
  object.parent = game.pov
  object.buy = null
  list remove (object.inventoryverbs, "Buy")
  player.money = game.pov.money - BuyingPrice(object)
  object.listalias = object.orignalalias
  msg ("You decide to buy " + object.article + " for " + DisplayMoney(BuyingPrice(object)) + ".")
}

The buy attribute script for the object is now

if (object.price > game.pov.money) {
  msg ("You can't afford that!")
}
else {
  object.take = true
  object.parent = game.pov
  object.buy = null
  list remove (object.inventoryverbs, "Buy")
  player.money = game.pov.money - BuyingPrice(object)
  object.listalias = object.orignalalias
  msg ("You decide to buy " + object.article + " for " + DisplayMoney(BuyingPrice(object)) + ".")
}