diff --git a/src/Battling/ScriptHandling/ScriptAggregator.hpp b/src/Battling/ScriptHandling/ScriptAggregator.hpp index e5b56ac..e8711d3 100644 --- a/src/Battling/ScriptHandling/ScriptAggregator.hpp +++ b/src/Battling/ScriptHandling/ScriptAggregator.hpp @@ -25,6 +25,9 @@ namespace CreatureLib::Battling { _index++; while (HasNext()) { if (_scripts[_index].HasValue()) { + if (_scripts[_index].IsSet()) { + _setIndex = -1; + } return; } _index++; diff --git a/tests/BattleTests/ScriptTests/ScriptAggregatorTests.cpp b/tests/BattleTests/ScriptTests/ScriptAggregatorTests.cpp index 3cc105c..7b53bc4 100644 --- a/tests/BattleTests/ScriptTests/ScriptAggregatorTests.cpp +++ b/tests/BattleTests/ScriptTests/ScriptAggregatorTests.cpp @@ -132,24 +132,30 @@ TEST_CASE("Script Aggregator properly iterates multiple script sets.") { BattleScript* script1 = new TestScript("test"); BattleScript* script2 = new TestScript("test2"); BattleScript* script3 = new TestScript("test3"); - BattleScript* script4 = new TestScript("test4"); - auto ran = 0; auto set1 = ScriptSet(); set1.Add(script2); set1.Add(script3); auto set2 = ScriptSet(); set2.Add(script1); - set2.Add(script4); auto vec = ArbUt::List{ ScriptWrapper::FromSet(&set1), ScriptWrapper::FromSet(&set2), }; auto aggr = ScriptAggregator(vec); + auto ran = 0; while (aggr.HasNext()) { auto next = aggr.GetNextNotNull(); next.value().As()->TestMethod(ran); } - CHECK(ran == 4); + CHECK(ran == 3); + + aggr.Reset(); + ran = 0; + while (aggr.HasNext()) { + auto next = aggr.GetNextNotNull(); + next.value().As()->TestMethod(ran); + } + CHECK(ran == 3); } TEST_CASE("Script Aggregator properly iterates when empty.") {