Array Index Wrapping?

This may be a little obscure, but if one wants to index an array in a wrapping type fashion (array[last index + 1] = array[index 0]) you can simply use mod(array length). However, this does not work for negative indexes, as in the example below. It results in a lot of clutter in my BPs. I’m wondering if anyone has figured out some macro that could be made for that, basically just a way to do it without using the branch/variable. Thanks

OK, braindead simple solution found. :sweat_smile: Guess I’ll leave this up for a bit in case it benefits anyone.

3 Likes

thanks for sharing.

curious what happens afterward though. Like without a branch, how is any sort of decision made about what to do?

In a lot of cases there’s no decision to be made, like if this was selecting the previous item in a wrapping menu. Or in my case I’m finding the angle at each point of a polygon by referencing the prev and next point. If there’s decisions though, depending on if your index is out of bounds, then you’d have to add branches in anyway, but at least with this you still wouldn’t need a new variable for your negative wrapped index.

1 Like

thanks!

i’ll give it a go. I’ve wondered similar thing for some time but I’m awful with math :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.