Using SugarCube 2.1x.x
I tried recently to implement a Quest system that works with "templates" of different quest types (fetch quests, put given number of items into a specified container, visit a location and check game time while doing so, defeat an enemy type etc.), where I would have a MissionLog object for each mission these would be elements of a set. These sets would represent accomplished and still on going missions.
When a mission is complete I would move the mission from the on-going mission into the accomplished set.
<<set accomplished_mission = new Set()>>
which yields "something" (I'm not sure what it is, probably a malformed array.)
I refer to this set in my JS code as follows:
When I try to add() new elements to this "set" using JS code, for some reason, the system ignores the fact that I requested to work with a Set() data structure and creates multiple instances of the same object inside accomplished_mission. I checked for the "isArray()" property to find out what I'm working with but it yielded a big undefined for me. So, I'm not sure what is going on here. I found my self opening the console next to Twine 2 and trying everything that came to mind to find out more about the data structure that I got from SugarCube 2.
Now, of course it's needless to say that there is an easy workaround for this kind of problem in JS (simply check if the "set" already holds the item with the same Id and filter any new additions), but the fact that things don't work the way they supposed to, kind of bothers me. I'm afraid things like these could come back and bite me in the a$$ later down the road as I develop my game in SugarCube 2. I never thought I'd run into so many problems, which have delayed me significantly.
Can anyone explain to me what is going on here and why are data structures and some standard JS functions behave so strangely?