If I'm not mistaken, you're referring to your Highest Step Number Calc node?
Here's what your node logic looks like:
let E-Vals = List of E-Values to search for a maximum in
let E Max= Current Maximum
if element at index (length E-Vals) of list E-Vals >= E Max
then Return the Highest Step Number with the same E Max and searching the rest of E-Vals
otherwise Return the length of E-Vals
There are some problems here.
- Lists are indexed at 0. If a list has only 1 element, it's length is 1, and the only element is at index 0. Therefore, if you try to get the length of the list and use that as an index, it will never work. Subtracting the length by 1 is the best approach (you see this a lot in actual programming). The reason you saw this when you subtracted 1 is because at length 0, you're trying to access index -1, which is also invalid.
- Your recursion may end before you've searched the entire list. For example, if the if node takes the false branch, then recursion ends. However, it's not guaranteed that you've traversed the entire list at this point; the actual maximum may still be in there. The recursion should end ONLY when the whole list has been processed.
Here are my proposed changes:
For starters, make your if node check if the list is empty. You can do this by using the isEmpty? node, which will return true if a given list is empty. Obviously you'll want to hook E-Vals into this.
For the true branch: if the list is empty, then the obvious maximum is the one we already have. So simply connect E Max to here.
For the false branch: if the list is not empty, then we need to perform some recursion. We can calculate the new max by taking the first element in the list and then comparing it with E Max. Whichever is bigger is what we will pass in as the new E Max. For the new E-Vals, we already checked the first element of our current E-Vals, so we need to search the rest of E-Vals.