Template: ROPE - ThePix/QuestJS GitHub Wiki

A rope is an object that can be attached at one or both ends. It can be "tethered", in which case one end is permanently attached to something. The ROPE template includes the TAKEABLE template.

Ropes are tricky things, and it is worth mentioning how they are implemented, if only to ensure it is documented somewhere. A rope has two ends, designated 1 and 2 - but they are assumed to be identical and interchangeable. If a rope is tied to something, then either "tiedTo1" or "tiedTo2" will be set to its name. If both ends are tied to objects, then both "tiedTo1" and "tiedTo2" will be set. In addition, the "locs" is an array of locations the rope passes through, starting at the 1 end and terminating at the 2 end.

Be aware that if you try doing anything weird with a rope, you find you need to do a lot of coding. In particular, ROPE objects have no "moveFromTo", so if you start moving the rope - or an end of it - in your custom code, you have some extra work to do.

This example gives a rope that will stretch between 7 rooms.

createItem("rope", ROPE(7), {
  loc:"hallway",
  pronouns:lang.pronouns.massnoun,
  indefArticle:'some',
})

By default a rope can be attached to any object that has "attachable" set to true, but you can give a rope its own "canAttachTo" to make it more discerning. In the example, the rope is a cable that can only be attached to items where "socket" is true.

    canAttachTo:function(item) {
      return item.socket
    },

You might also want to have your own "attachTo" and "detachFrom" function attributes. Both are sent the character and the item the rope is to be tied to or untied from. If these tell the user what happened, you should set "suppessMsgs" to true to stop the default messages getting printed too. Bear in mind that you will need to work out which end of the rope to handle in both of these.

Life is a little easier if the rope is tethered - i.e., permanently attached at one end. We then know "attachTo" and "detachFrom" concern only end 2.

This example shows a tethered rope; in this case some wire permanently fixed to a strange device. Note also custom "msgUnwind" and "msgWind" messages; these are used as the rope is played out and picked up again.

createItem("wire", ROPE(7, "strange_device"), {
  loc:"mad_science_lab",
  alias:"wire",
  parserAltNames:['coil'],
  pronouns:lang.pronouns.massnoun,
  indefArticle:'some',
  msgUnwind:"The wire trails behind as Mandy unwinds it.",
  msgWind:"Mandy coils up the wire.",
})