DesignScript AddList function or incremental sum calculation in Dynamo 2.13.1

Hello everyone. This may come as a basic syntax issue for some, but I can’t seem to be able to figure it out by myself. I have used an AddList function in Dynamo 2.12.1 in order to obtain an incremental sum calculation from a given list. Say from [5,10,20,50] I would get a new list [5,15,35,85]. Essentially x=sum(0…x-1). The DesignScript Function looks like this (I am not the original author of this code and I can’t seem to find where I got this from originally. Credits to be added):

def AddList (Num:var[])
{
y=[];
collection=0..(DSCore.List.Count(Num)-1);
x=DSCore.List.GetItemAtIndex(Num,0);
return=[Imperative]
{
for (i in collection)
{
y[i]=x;
x=Math.Sum([x,List.GetItemAtIndex(Num,i+1)]);
}
return=y;
}
};

In Dynamo 2.12.1 it works great, however, the code no longer works in Dynamo 2.13.1 and returns the first element and otherwise an empty list. Any ideas on how to fix it (and why it stopped working in the newer Dynamo version)?
Many thanks in advance!


P.S. I am aware that the incremental addition issue has been solved here, I am trying to figure out why the same DesignScript code bahaves differently between different dynamo versions.

Hello, I’m on 2.13 too.

try to play with the level of the lists (Maybe)

by putting the same variable in the 2 code blocks (I have an error, maybe this side)

Cordially
christian.stan