Skip to content

Commit

Permalink
Eek, fix for (apparently!) long standing gather read count bug
Browse files Browse the repository at this point in the history
  • Loading branch information
joethephish committed Aug 13, 2018
1 parent 09fef6c commit a17baa6
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ink-engine-runtime/Story.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
70 changes: 70 additions & 0 deletions tests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a17baa6

Please sign in to comment.