jaynabonne wrote:You can also use the dictionary form of ShowMenu (mapping object to display name), which eliminates the need to find the object from the display name once chosen (and will work properly if multiple objects have the same display name, which shouldn't happen, but...). If you use the dictionary form, then the result will just be the desired object.
Good point, that is better:
// Lines starting with two slashes are comments so you know what is happening!
// Get a dictionary of the names of the objects held
// Start from an empty dictionary
string_dict = NewStringDictionary()
// Loop through each item held, and add its name and display name to the dictionary
foreach (obj, ScopeInventory()) {
// Add to the dictionary
// the name is the key, the display name is the value
dictionary add (string_dict, obj.name, GetDisplayName(obj))
}
// Show the menu (shows the values from the dictionary)
ShowMenu ("Pick an item", string_dict, true) {
// The selection key goes in a variable called "result"
obj = GetObject(result)
// Do stuff weith it
msg ("You selected the " + GetDisplayName(obj))
}