SCI1.1 Advanced Inventory Items

We now know how to add inventory items, as well as code complex interactions in a room. Now we are going to combine those two bits of information and apply that to the inventory items.

Before we begin, let's go ahead and create a second item. In the first tutorial on Inventory items, we made an instance for testItem, now let's go ahead and make another one named antiTestItem. Just like with our first item, we will also need to add antiTestItem to the add list, create the views and cursor, as well as add in the noun and verb to the message resource. In the file, I am going to assume you defined it as ITEM_ANTITESTITEM. If you have no idea what it is that I am talking about, might I suggest going over the chapter Creating Inventory Items again.

But if you are ready, lets go ahead and start with our basic instance. It is from here that we are going to build

Code: [Select]
(instance antiTestItem Sq5InvItem
        view 902
        loop 1
        cel 0     
        cursor 902
        message V_COMBINETEST
        signal $0002
        noun N_COMBINETESTER

Using an item on another item

It is very common to need to combine two or more inventory items. The easiest way to accomplish this is to check for the use of a verb. Our first item we created in the other chapter, we defined the verb associated with it as V_TEST. So really all we need to do is check for the verb noun combination of the two items. To do that, just like we did with Complex Interactions we are going to add a doVerb method to our inventory items instance. For our purposes here, when the original test item is used on the anti test item, simply drop the test item.

Code: [Select]
  (method (doVerb theVerb param2 param3)
    (switch (theVerb)
      (case V_TEST
          (sq5Inv:hide()) // hides the current window
          (send gEgo:put(ITEM_TESTITEM)) // drops the test item
          (sq5Inv:curIcon(0)show(gEgo))// changes cursor and shows ego's items
     (super:doVerb(theVerb param2 rest param3))
   )// ends verb switch
  )// end method

In most cases like this, you are actually going to want to drop both original items and replace them with a third item which represents the other two combined. If that is the case, then you would simply need to alter the send gEgo line.

Code: [Select]
          (send gEgo:put(ITEM_ONE)put(ITEM_TWO)get(ITEM_THREE))

Extending the Money Item to include amount in description