I'm cleaning up some of my code and using more loops generally leads to clean-looking results. However, I've always been reluctant to use more loops than necessary and I'm curious about whether it's the amount of times a loop runs vs. what happens in the loop that puts the biggest load on fusion.
For example: I've been using a loop that checks the array contents surrounding a given pair of XY coordinates. The loop used to look something like this:
... that is, one event for each of the 8 array slots to check.Code:+On Event - Start Loop "scan" 1 time +On Loop "scan" +ArrayXY (X+ -1, Y+ -1) == bla - Trigger something +On Loop "scan" +ArrayXY (X+ 0, Y+ -1) == bla - Trigger something +On Loop "scan" +ArrayXY (X +1, Y -1) == bla - Trigger something (+ 5 similiar events) etc...
I cleaned it up, and now the loop is called once for each slot instead, like this:
Code:+On Event - slotX = -1 - slotY = -1 - Start Loop "scan" 9 times + On Loop "scan" +ArrayXY (X +slotX, Y +slotY) == bla - Trigger something + On Loop "scan" - slotX++ + On Loop "scan" + slot X > 1 - slotY++ - slotX = -1
I haven't noticed any difference in performance so far, and the second is preferable as it's much cleaner. So I basically I wonder what's generally the best practice here![]()





Reply With Quote


)



