-
-
Save ChapelR/bcbcb08d3db2a1df60c16de73344ee20 to your computer and use it in GitHub Desktop.
// 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; |
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.
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.
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!
Usage:
Place code like this in a
header
-tagged passage.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.