Skip to content

Commit 15a1681

Browse files
fix repeat loop caching input value
1 parent 621a6f1 commit 15a1681

1 file changed

Lines changed: 7 additions & 13 deletions

File tree

Code/ContextSystem/Contexts/Control/Loops/RepeatLoop.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace SER.Code.ContextSystem.Contexts.Control.Loops;
1313
public class RepeatLoop : LoopContextWithSingleIterationVariable<NumberValue>
1414
{
1515
private readonly Result _rs = "Cannot create 'repeat' loop.";
16-
private ulong? _repeatCount = null;
1716
private Func<TryGet<ulong>>? _repeatCountExpression = null;
1817

1918
public override string KeywordName => "repeat";
@@ -70,27 +69,22 @@ public override TryAddTokenRes TryAddToken(BaseToken token)
7069
public override Result VerifyCurrentState()
7170
{
7271
return Result.Assert(
73-
_repeatCountExpression != null || _repeatCount.HasValue,
72+
_repeatCountExpression != null,
7473
_rs + "The amount of times to repeat was not provided."
7574
);
7675
}
7776

7877
protected override IEnumerator<float> Execute()
7978
{
80-
if (!_repeatCount.HasValue)
81-
{
82-
if (_repeatCountExpression == null)
83-
throw new AndrzejFuckedUpException("Repeat context has no amount specified");
79+
if (_repeatCountExpression == null)
80+
throw new AndrzejFuckedUpException("Repeat context has no amount specified");
8481

85-
if (_repeatCountExpression().HasErrored(out var error, out var val))
86-
{
87-
throw new ScriptRuntimeError(this, error);
88-
}
89-
90-
_repeatCount = val;
82+
if (_repeatCountExpression().HasErrored(out var error, out var val))
83+
{
84+
throw new ScriptRuntimeError(this, error);
9185
}
9286

93-
for (ulong i = 0; i < _repeatCount.Value; i++)
87+
for (ulong i = 0; i < val; i++)
9488
{
9589
SetVariable(i + 1);
9690
var coro = RunChildren();

0 commit comments

Comments
 (0)