Taking Inventory Item away from character

From SCI Wiki
Revision as of 02:02, 17 January 2011 by Andrew Branscom (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

By Cloudee1

This is a pretty basic need, perhaps you have given the golden ring to the potion maker or say you eat the spinach dip, either way your character will need to "lose" the inventory item.

This is not covered in any of the tutorials, but has been covered enough at our old home that we all know how to do it, but any new members won't. I figured I had better stick this up here so anyone new to sci won't have to ask. I remember I asked when I first started out.

Anyway, if you have done the tutorial, which if you haven't you should, then you will remember that in order for your character to get an item you needed to use the code

Code:
(send gEgo:get(INV_KEY))

Now to drop an item either when your character uses it, gives it away, or simply drops it, you could use put instead of get.

Code:
(send gEgo:put(INV_KEY))

in whatever room your character got the item, if you checked to see whether or not gEgo had it before initing it, then the item will reappear there since your character no longer has the item. This may seem strange if the person used the item, or gave it to someone else. Handling these type of instances will require using global variables.

However, with this method in whatever room your character got the item, if you checked to see whether or not gEgo had it before initing it, then the item will reappear there since your character no longer has the item. This may seem strange if the person used the item, or gave it to someone else. Handling these type of instances will require using global variables. In these cases, you really want to test whether an object is in the room or not. An inventory object has an owner property and an ownedBy() method. The way Sierra used to do things was set the owner field to the number of the room the object is in. The (ego get:), (ego put:) and (ego has:) methods simply use this property. You can then test for ownership by doing:

Code:
(if (send anItem:ownedBy(gRoomNumber)) ...)

This allows items to move around in the game. You can also use objects as owners, if you prefer; indeed, this is already done when an item is in the player's inventory. Additionally, you'd also want to know about:

Code:
(send gEgo:put(anItem gRoomNumber))

It will not take it from inventory and make it appear on the screen. The concept of an inventory item is completely different from the visual representation of it that you might see in the room. You would check to see if the room "owns" the inventory object prior to going ahead and initializing the Prop instance (or whatever) that represents that object in the room. Also, there is a position associated with it when it's in the room, but not in your inventory.

The initial "owner" room is specified in the inventory object:

Code:
(instance {Thermal Detonator} of InvI
    (properties
        said '/detonator'
        description "Used for blowing stuff to little bits.   It has an impact switch, so in other words...DON'T DROP IT!"
        owner 69
        view 242
        loop 0
        cel 12
    )
)