Template ‐ SHIFTABLE - ThePix/QuestJS GitHub Wiki
An item that is shiftable can be pushed or pulled from one room to another, in any direction where there is an exit, other than up.
createItem("crate", FURNITURE({stand:true}), SHIFTABLE(), {
loc:"conservatory",
examine:"A large wooden crate, probably strong enough to stand on.",
})
The player can now do PUSH CRATE NORTH, and shift the crate into another room, perhaps where standing on a crate is useful.
The template itself just sets "shiftable" to true
, all the real work is done in the command (specifically the "handlePushExit" function).
You can give the item its own shift
attribute for more control over the process. This should return a Boolean indicating success or failure, and take three parameters, the character doing the pushing, the direction and the verb (in case you want PUSH to do something different to PULL).
You can set an exit to stop items being pushed though it by giving it a noShiftingMsg
, which can either be a string, or a function that returns a string, and takes the character and item as parameters.
That is all there is to it!
Events
If you want to react to an item being shifted, you can use the "onMove(toLoc, fromLoc)" attribute, which is fired when any object is moved (eg see here). This will fire if the object is picked up, so that could be an issue; Quest assumes an item that is shiftable cannot be picked up.