0 votes
by (320 points)
I was planning on using tags to give attributes to passages that determine how some links behave and to set the player's location, and the order of the tags was important, but it seems unusable in Sugarcube 2.

For example, I have a passage with the tags, "locale, Your-Apartment, Bedroom". I have some code in a few places that behaves differently depending on if the first tag is "locale" or not, and then also displays the other two tags in order(as "general location" : "specific room").

However I immediately got errors, and it's because the tags() array isn't in the same order as they appear in the editor. When I printed the tags() function, it came out as "Bedroom, Your-Apartment, locale". At first I thought it was just reversed, but even switching the tags around results in the same exact array.

I wondered if it was an issue with Twine itself, but the tags seems to be in the correct order in Harlowe. Which isn't really helpful since I don't use Harlowe.

I managed to make a work around(albeit a bit less convenient than just using tags), so I'm not looking for a solution per se, but I'm still left wondering why this happens and if it's an oversight.

1 Answer

0 votes
by (63.1k points)
Tags are sorted using a standard JavaScript array sort method when the passage is built by the engine. Tags aren't really a good fit for a lookup table situation anyway, though you could instead do something like "location:bedroom", then look that up. You could also just build a completely separate data structure with the info you need.
by (68.6k points)
Tags are sorted as part of the process of duplicate removal.  Their ordering has never been guaranteed.