Hi everyone.
I have this very complicated question to explain over here. So basically, this is the data table:

I'm supposed to create a column called "Total Coordinates Around You" using JSL script, by imagining that there are 8 squares around the particular coordinate (excluding its own coordinate basically), as shown by the picture below, where the small blue circle represents this particular coordinate. Thus, the maximum "Total Coordinates Around You" is 8. For example, as shown by the picture above, by the number 9998887, coordinate (-2,1) has got a "Total Coordinates Around You" of 3, which are (-2,2), (-1,1) and (-1,0). Just for a note, the horizontal axis represents shift in x-coordinate and likewise, the vertical axis represents shift in x-coordinate. From the data table above, it is easy to make 20 "Total Coordinates Around You", but in my actual tasks, there are about 23,000+ rows to be dealt with. Also, one more thing, I'm supposed to sort the numbers according, like 9465371 and 9998887 shown in the data table above, respectively (they got the same coordinates), before working on the "Total Coordinates Around You".

dt = current data table();
dt << New column ("Total Coordinates Around You",
numeric,
continuous,
formula (
For ( i = 1, i<= N Row(), i++,
(:Total Coordinates Around You = 0; munipulated_x = :X-Coordinate - 1; munipulated_y = Y-Coordinate - 1; j = 1; k = 1; formula (
For ( j = 1, j <= 3, j++,
(formula(
For ( k = 1, k <= 3, k++,
(formula( If (munipulated_x == :X-Coordinate & munipulated_y == :Y-Coordinate, :Total Coordinates Around You))
; munipulated_y ++)
)
) ; munipulated_x ++)
)
) ; :Total Coordinates Around You --)
)
)
);Above is a script which I created, which I'm not sure why this can't be worked, using loops. Can someone enlighten me on the steps and solutions on how to deal with this problem? There is a second part to this question, which I will try once I get my first part done. Do allow me to explain should there be any doubt especially on the clarity of the question and explanation, and once again, pardon me for the explanation. Thank you.