kts.ChangeItem – transform an item into another
kts.ChangeItem(new_item_type)
This function changes the type of the item at cxt.item_pos
(if any) to match the given new_item_type
.
In more detail: If any of cxt.item_pos
or cxt.item
or new_item_type
are nil
, then this function does nothing. Otherwise, any item currently at position cxt.item_pos
is destroyed, and then a newly generated item of type new_item_type
is created and added to the dungeon at that same position.
None.
This function raises an error in any of the following cases:
cxt
global variable is undefined or invalid cxt.item_pos
is neither a valid map position, nor nil
(Note: a "valid map position" means a table containing fields x
and y
giving the co-ordinates of a particular dungeon square) cxt.item_type
is neither a valid ItemType nor nil
new_item_type
is neither a valid ItemType nor nil
The bear trap item provides an example of this function being used. When an open bear trap is walked over by a creature, or hit with a weapon, the kts.ChangeItem
function is used to change it into a closed bear trap. See items.lua.