Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

[Harlowe][Twine2] Is it possible to set a value in a Datamap to a reference to a different Variable?

I'm starting to learn Twine, and I thought I'd go about making a small framework to familiarize myself with the system.
What I'm trying to do is set up a Datamap called "Door" that has a key/value pair of "openCondition",$doorUnlocked.
Now what this does is set "openCondition" to whatever $doorUnlocked was when "Door" was created. That's fine, but what I need is "openCondition" to be a reference to $doorUnlocked so that when $doorUnlocked changes, "openCondition" changes as well.

Is this something that can even be done in Harlowe? If so how?
If not, does it work in Sugarcube or any other format?

Thank you for your time.


  • I asked around, and it doesn't look like it's possible. If you're interested in details check out this Stack Exchange question.
  • warning: The following information has been simplified, which means that why the basic premise is correct the actual technical details are not 100% accurate.

    To add to the following information from the Stack Exchange thread.
    DataMaps are implemented using JavaScript Maps, and whenever a value is set on them, it seems to clone() the value before assigning it.
    There is a further complication to what you are trying to do, and that is that each time passage traversal occurs the current state of all known story variable is 'copied/cloned'. The original is associated with the previous passage in the History System while the copy is made available to the new passage about to be shown.

    This copying process causes internal object references to break, because the 'child' objects they reference to are also being copied. Which results in references that were originally pointing to the same object to now each be pointing to their own unique copy of that object.

    This is why it is generally better store the 'property name' or 'index' of the associated object instead of the reference to that object.
    Assign the second person as the leader of the party.
    (set: $people to (array: "aaaa", "bbbw", "cccc"))
    (set: $party to (datamap: "leader", 2))
    person 2: (print: $people's 2nd)
    leader: (print: $people's ($party's leader))
    Fix spelling of second person's name.
    (set: $people's 2nd to 'bbbb')\
    person 2: (print: $people's 2nd)
    leader: (print: $people's ($party's leader))
    ... this technique is not effected by passage traversal.
Sign In or Register to comment.