482
« on: August 29, 2011, 05:01:52 PM »
Ah, those are nodes of a linked list indeed, as Lance suggested. A linked list is a list of objects that makes no commitment to size. So it can grow as large as you have memory, or it can shrink to nothingness when it contains no elements. Furthermore, linked lists make it easy to move back and forth between the elements of a list (to perform some action on each, say) and remove specific elements - the List class has a number of methods to facilitate this (but they are not used in your code excerpt). That is to say, the elements of a linked list are stored in the same order we added them, and so this order must be stored somewhere. However, since we cannot claim any space in the objects that are put in a list (what if one SCI object is a member in many different lists?), this information gets stored somewhere else. And that place is the node.
(There's more to the story, of course, but we can get to that another day)
As you say, the purpose here is to set up the text and buttons of an inventory dialog (but not to show it - that comes elsewhere).
So, to answer a not entirely unrelated question: No, this not the right place to add support for the look idiom. The right place is the global handleEvent method.
In there, say something like (I'm not entirely fluent in Brian's syntax; I hope you can massage this into working code):
(if (Said('look >'))
= lookObject (send gInv:firstTrue(#saidMe))
(send lookObject:showSelf())
)
Now, let's take that very slowly. I mentioned above that linked lists (List class) have some methods designed to facilitate going through the members of a list in order. In this case, we want the first element in the inventory list whose saidMe method returns TRUE. And when does that happen? When the remaining part of the user input corresponds to that object's said property (this should only happen for one object - otherwise you should perhaps rethink the names of your inventory items). Note that this means you must set the said property correctly! As soon as firstTrue finds an object for which saidMe returns TRUE, it returns a pointer to that object. We can then ask the object directly to show itself (as the inventory dialog already does).