I´m pretty sure your function does work for 0, however, it gets overwritten later down the line.
I´ve marked all the cells containing 0 in your array, all those will be checked inside the "For each XY element" loop, then icons will be picked where "id = int(tokenat(Array.At(Array.CurX,Array.CurY),3,", "))" will resolve to "0", then the text will be set to "tokenat(ArrayAt........." which also resolves to 0 and then the icons animation frame will be set to "int(tokenat(.........." which again resolves to 0.
I think the easiest fix would be to add a regex check before you pick icons to see if you are actually on cell that contains the relevant data, so something like
If that isn´t the fix I can only help you if I get my hands on the events.