How to Make ShowMenu Display Inventory (Objectlists)

Dcoder
08 Dec 2016, 10:25

This must be a simple problem to solve, but I've spent hours researching/experimenting with this and it still won't work. I've made a "trade" verb that should bring up 2 menus: one displays the player's inventory (asking what the player offers) and the other displays a merchant's sell list (asking what the player wants). Here's the code:

givableList = ScopeInventory()
ShowMenu ("What do you offer?", givableList, true) {
  result = OfferedItem
  ShowMenu ("What do you want?", MerchantSellList, true) {
    result = WantedItem
    if (OfferedItem = xyz) {
      MoveObject (OfferedItem, Inactive)
      AddToInventory (WantedItem)
      list remove (MerchantSellList, WantedItem)
    }
    else {
      msg ("The merchant does not want that.")
    }
  }
}

In the game, when I type "trade merchant", it will print "What do you offer?" and then return this error:

Error running script: Unable to cast object of type 'TextAdventures.Quest.Element' to type 'System.String'.

It sounds like I've created an objectlist, but ShowMenu will only display stringlists? Where does the code need correction? Help!


Pertex
08 Dec 2016, 15:01

ScopeInventory() returns a list of objects, but ShowMenu requires a list of strings

givableList = NewStringList()
foreach (item, ScopeInventory() ) {
	list add (givableList, item.name)
}
ShowMenu ("What do you offer?", givableList, true) {
  OfferedItem = GetObject(result) 
  ...
}