Moving a Prop from Inventory to Room

From SCI Wiki
Revision as of 16:45, 5 August 2013 by Andrew Branscom (talk | contribs) (1 revision)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to 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:


Code:
(instance keyOnTable of Prop
    (properties
        x 100
        y 130
        view 100
    )
)


In your room's init method:

Code:
// 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))
    (keyOnTable:init())
)


Then in the RoomScript's handleEVent method:

Code:
(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
    )
    (else
        Print("You don't have the key")
    )
)