0
Pending Review

Nested for loop overshoots last index

TowerCrow 3 months ago updated by Lazlo Bonin (Lead Developer) 6 days ago 4

Looks like it overshoots, and after item 3 it does one extra iteration on item 0 the second time.

The dictionary is completely empty before running the logic:

The dictionaries are generated correctly even with the error present:

[Exception] ArgumentException: Item has already been added. Key in dictionary: 'fanPoints'  Key being added: 'fanPoints'
Hashtable.Insert() <567df3e0919241ba98db88bec4c6696f>:0

Hashtable.Add() <567df3e0919241ba98db88bec4c6696f>:0

OrderedDictionary.Add() :0

AddDictionaryItem.Add() C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Framework/Collections/Dictionaries/AddDictionaryItem.cs:82

Flow.InvokeDelegate() C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Flow.cs:447

Flow.Invoke() C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Flow.cs:341

For.Loop() C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Framework/Control/For.cs:92

Flow.InvokeDelegate() C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Flow.cs:447

Flow.Invoke() C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Flow.cs:341

Flow.Invoke() C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Flow.cs:345

Sequence.Enter() C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Framework/Control/Sequence.cs:61

Flow.InvokeDelegate() C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Flow.cs:447

Flow.Invoke() C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Flow.cs:341

Flow.Run() C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Flow.cs:244

Bolt.EventUnit`1[TArgs].Run() C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Framework/Events/EventUnit.cs:179

Bolt.EventUnit`1[TArgs].Trigger() C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Framework/Events/EventUnit.cs:150

Bolt.EventUnit`1+<>c__DisplayClass14_0[TArgs].b__0() C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Flow/Runtime/Framework/Events/EventUnit.cs:69

EventBus.Trigger[TArgs]() C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Core/Runtime/Events/EventBus.cs:72

Bolt.EventMachine`2[TGraph,TMacro].TriggerRegisteredEvent[TArgs]() C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Core/Runtime/Events/EventMachine.cs:36

Bolt.EventMachine`2[TGraph,TMacro].TriggerEvent() C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Core/Runtime/Events/EventMachine.cs:14

Bolt.EventMachine`2[TGraph,TMacro].Start() C:/Users/lazlo/Projects/Bolt1/Package/Bolt.Core/Runtime/Events/EventMachine.cs:63

Here's the scriptable object var code that's in the list:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu]
public class IntVariable : ScriptableObject
{
public int intValue;
}
Bolt Version:
1.4.10
Unity Version:
2019.2.14
Platform(s):
PC
Scripting Backend:
Mono
.NET Version (API Compatibility Level):
.NET 4.x

I guess this would be the solution:



Weird that the first loop is successful but not the second though.
Need More Information

Hi TowerCrow,

I've been trying to parse what's going on here, and it's kind of hard to tell. Basically the only difference in the second attempt is the omission of Sequence, right? There's no other change in your setup whatsoever, even for initial variable contents? So Sequence would be causing the issue?

Sorry about the sequence there, it's actually not needed, I used it for testing to determine if sequential execution would change anything - it didn't. 

The difference in the solution image is to use "AoTDictionary new" as an input for Add Item unit instead of Get Saved Variable and then use Add Item output to save the dictionary with Set Saved Variable.  



Both solutions technically achieve the same thing, but the first one seems to overshoot and do one extra iteration when it shouldn't.