diff --git a/ink-engine-runtime/Story.cs b/ink-engine-runtime/Story.cs index b440858e..6cae7e04 100644 --- a/ink-engine-runtime/Story.cs +++ b/ink-engine-runtime/Story.cs @@ -761,7 +761,8 @@ void VisitChangedContainersDueToDivert() if (currentChildOfContainer == null) return; Container currentContainerAncestor = currentChildOfContainer.parent as Container; - while (currentContainerAncestor && !_prevContainers.Contains(currentContainerAncestor)) { + + while (currentContainerAncestor && (!_prevContainers.Contains(currentContainerAncestor) || currentContainerAncestor.countingAtStartOnly)) { // Check whether this ancestor container is being entered at the start, // by checking whether the child object is the first. diff --git a/tests/Tests.cs b/tests/Tests.cs index 1cb37378..658cb0c2 100644 --- a/tests/Tests.cs +++ b/tests/Tests.cs @@ -3518,6 +3518,76 @@ public void TestUsingFunctionAndIncrementTogether() // Ensure it just compiles CompileStringWithoutRuntime(storyStr); } + + // Fix for rogue "can't use as sub-expression" bug + [Test()] + public void TestKnotStitchGatherCounts() + { + var storyStr = + @" +VAR knotCount = 0 +VAR stitchCount = 0 + +-> gather_count_test -> + +~ knotCount = 0 +-> knot_count_test -> + +~ knotCount = 0 +-> knot_count_test -> + +-> stitch_count_test -> + +== gather_count_test == +VAR gatherCount = 0 +- (loop) +~ gatherCount++ +{gatherCount} {loop} +{gatherCount<3:->loop} +->-> + +== knot_count_test == +~ knotCount++ +{knotCount} {knot_count_test} +{knotCount<3:->knot_count_test} +->-> + + +== stitch_count_test == +~ stitchCount = 0 +-> stitch -> +~ stitchCount = 0 +-> stitch -> +->-> + += stitch +~ stitchCount++ +{stitchCount} {stitch} +{stitchCount<3:->stitch} +->-> +"; + + // Ensure it just compiles + var story = CompileString(storyStr); + + Assert.AreEqual( +@"1 1 +2 2 +3 3 +1 1 +2 1 +3 1 +1 2 +2 2 +3 2 +1 1 +2 1 +3 1 +1 2 +2 2 +3 2 +", story.ContinueMaximally()); + } // Helper compile function