Skip to content

Instantly share code, notes, and snippets.

@ChapelR
Last active May 9, 2021 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChapelR/bcbcb08d3db2a1df60c16de73344ee20 to your computer and use it in GitHub Desktop.
Save ChapelR/bcbcb08d3db2a1df60c16de73344ee20 to your computer and use it in GitHub Desktop.
Harlowe DM Loading patch
// goes in story JS; see conversation below;
// only games played via Twine 2 (web)'s play/test modes have the bug
delete Map.prototype.toJSON; delete Set.prototype.toJSON;
@ChapelR
Copy link
Author

ChapelR commented Aug 28, 2020

Usage:

Place code like this in a header-tagged passage.

(set: _dummy to window.patchDM("varName"))

Where varName is the name, without the $ sigil, of a variable containing a data map. You will need to do this for every data map in your game. This patch will not fix nested data maps.

@ChapelR
Copy link
Author

ChapelR commented Jan 22, 2021

THIS FIX WON'T WORK ANYMORE IN HARLOWE 3.2.0+.

The bug is still present, but changes to Harlowe further limit the ability of users to access the engine with JavaScript code, meaning that fixes like these are now basically impossible. While new workarounds could probably be found, it's not worth the effort IMO. If you need complex, collection variables in your game, use a different format.

@webbedspace
Copy link

webbedspace commented May 9, 2021

I'd like to register a complaint. The problem is not in Harlowe, but the copy of CoreJS that Twine 2 ships with, which installs a COMPLETELY NONSTANDARD implementation of Map.prototype.toJSON that has been off the spec for over 5 years. This is because Chris never changed TwineJS's package.json to use CoreJS 3.x, which removes this "polyfill".

Anyway, the takeaway of all this is that a solution DOES exist, WORKING in Harlowe 3.2.0, and it's this line:

delete Map.prototype.toJSON; delete Set.prototype.toJSON;

Something like this will be installed in a future version of Harlowe.

@ChapelR
Copy link
Author

ChapelR commented May 9, 2021

I'd like to register a complaint. The problem is not in Harlowe, but the copy of CoreJS that Twine 2 ships with, which installs a COMPLETELY NONSTANDARD implementation of Map.prototype.toJSON that has been off the spec for over 5 years. This is because Chris never changed TwineJS's package.json to use CoreJS 3.x, which removes this "polyfill".

Anyway, the takeaway of all this is that a solution DOES exist, WORKING in Harlowe 3.2.0, and it's this line:

delete Map.prototype.toJSON; delete Set.prototype.toJSON;

That's good to hear. At the time I wrote this, I thought the bug existed in compiled projects, so I thought the situation was more dire than it seemed, otherwise I wouldn't have bothered trying to patch it. That JS line does indeed fix it, so that's awesome. Thanks for the update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment