ChapelR / custom-macros-for-sugarcube-2

A collection of systems and macros for Twine.
https://macros.twinelab.net/
The Unlicense
166 stars 44 forks source link

Simple Inventory Containers Item Duplication #4

Closed AccreditedDesign closed 6 years ago

AccreditedDesign commented 7 years ago

I've discovered a bug regarding item duplication when <<container>> is used in ::PassageFooter like this: <<if not tags().includes("nofooter")>>\ <span id="borderbox"><b>Visible Items: </b><<container>> <<message 'Inventory' btn>><<droplist>><</message>> </span>\ \<</if>>

To produce item duplication:

  1. Enter a container with items placed in it (from the ::StoryInit).
  2. Pick up the items.
  3. Stay in the same passage and immediately click drop on the items several times. Literally spam-click on the same drop link.

For every time you click drop, an additional duplicate instance of that item is added to the passage's inventory, visible in <<container>> upon a revisit to the passage. You of course have to leave that passage and then come back into it to see the refreshed <<container>> items. So, what I notice happening is that when drop is clicked, the item and drop link remain visible in the <<droplist>> when they should be removed upon clicking, allowing an anxious player the possibility of clicking drop multiple times and thus somehow producing duplicate items, which seems to also break other things later such as <<has>>.

Here's an example story where this occurs: https://goo.gl/PAQLSS

In the linked example it is interesting to note that the passage ::Flower Pot does this upon the very first visit to the passage. However the passage ::Old Cabin Chest does not do this right away, and actually appropriately removes the item and drop link from the <<droplist>> when clicked. However... if you leave the ::Old Cabin Chest passage after the first attempt to reproduce the bug, and then revisit it one or perhaps two times, it will eventually start to show the behavior and also begin generating duplicate items via not removing the item and drop link from <<droplist>>.

ChapelR commented 7 years ago

I'll take a look at this as soon as I can.

ChapelR commented 7 years ago

I'll need to do some soul-searching to find a complete fix to the actual underlying problem, but here's a workaround that should help.

::PassageFooter
<<if not tags().includes("nofooter")>>\
<span id="borderbox"><b>Visible Items: </b>@@#cont;<<container>>@@
<<message 'Inventory' btn>>@@#drpl;<<droplist>>@@<</message>>
</span>\
\<</if>>

In Story JavaScript:

// containers message patch
$(document).on('click', '.droplist-link, .macro-container-link', function () {
    $('#cont').empty().wiki('<<container>>');
    $('#drpl').empty().wiki('<<droplist>>');
});

I'll update the repo once I figure out a better/more efficient way.

I'm sorry that this system is so buggy, and do let me know if this fix works and if you encounter any other issues.

AccreditedDesign commented 7 years ago

From a quick test, the patch seems to work. Thanks again Chapel. And don't apologize, I build things too and understand that no project goes out at absolutely 100% the first time. It's an excellent system and aside from the few little burps it works extremely well. I'd say your batting average is pretty high.

ChapelR commented 6 years ago

Well, I never did fix this bug, but the new simple inventory system (v2.1.0+) has support for containers out of the box (though in a different, more sane way), and I'm no longer going to be recommending the use of or developing and maintaining passage-containers.js. So I'm calling this closed.