Showing a menu of player inventory

Is there a way to print out a menu that shows a player's inventory, I am adding an upgrade mechanic into my game so I want the player to be able to choose a weapon to upgrade.


Something like:

ShowMenu ("Choose an item to upgrade", ScopeInventory(), true) {
  // the variable 'result' here is the *name* of the chosen item
  // Use 'GetObject(result)' to get the actual item
}

You might also want to do something like:

weapons = NewObjectList()
foreach (item, ScopeInventory()) {
  if (some way to test if an item is a weapon that can be upgraded) {
    list add (weapons, item)
  }
}
if (ListCount (weapons) > 0) {
  ShowMenu ("Pick a weapon to upgrade…", weapons, true) {
    // as before, result is the *name* of the chosen item
    // Doing it this way, only the relevant type of items are listed
  }
}
else {
  msg ("You don't have anything you can upgrade.")
}

How would I test if an object is a weapon? I know about flags but I don't know how to test for multiple objects.


If you've got an "is a weapon" flag, the expression in that if statement would just be GetBoolean(item, "isweapon"), or whatever the name of the flag is. Although in that case there's a function to do the first loop for you:

weapons = FilterByAttribute (ScopeInventory(), "isweapon", true)
if (ListCount (weapons) > 0) {
  ShowMenu ("Pick a weapon to upgrade…", weapons, true) {
    // code to upgrade result goes here
  }
}
else {
  msg ("You don't have anything you can upgrade.")
}

So can I have this work for a section in the inventory, I am organizing the inventory into sections so I have a container in the inventory for weapons.


In that case, just replace ScopeInventory() with GetDirectChildren (weapons) (or whatever your weapons container is called).


If I use an if script how would I get the result, or is there a better way?


I found a way to do it, thanks for the help!


Log in to post a reply.

Support

Forums