Moving a Prop from Inventory to Room

From SCI Wiki
Jump to: navigation, search

By troflip

To make an object in inventory, such as a key, appear on the screen and be removed from the inventory, if the inventory item is identified with INV_KEY, you can use this code.

In your room, define a key Prop:

(instance keyOnTable of Prop
        x 100
        y 130
        view 100

In your room's init method:

// If the inventory key is owned by this room, make the "key on table" visual show up:
(var invItem)
(= invItem (send gInv:at(INV_KEY)))
(if (send invItem:ownedBy(gRoomNumber))

Then in the RoomScript's handleEVent method:

(if (Said('put/key/table'))
    (if (send gEgo:has(INV_KEY))
        (send gEgo:put(INV_KEY gRoomNumber)) // Give inventory key from the ego to the room
        (keyOnTable:init())                  // Make the "key on table" visual show up
        Print("You don't have the key")