Reverse Array Count Not Working Properly

I have a button to siphon through an array of cameras and I am trying to make a reverse button for the index but the button with the reverse node acts erratically when pressed, either just going to the next camera like the other button without the reverse node, or not doing anything at all. The “back” button works just fine but when I try to add the reverse node or use a subtract one, it wigs out and doesn’t work right.

Why not just use the index of the array of the cameras?
Use an int for the current camera and wrap it to the amount of cameras.
One button increases the index, the other decreases, finally wrap index to keep in the array bounds.

1 Like

Isn’t that what this is doing in the event graph? I use the “GET” node to grab the array and use the index to go through it one by one, though I would prefer to be able to select each camera individually, as I think that would be a more user friendly method.

It’s changing the order on every reverse: index 1 would be the second camera but when reversed and moving 1 left it would select the last camera, not the first one.

For the index to wrap around going left do this: (index - 1 + Length) % Length. No need to reverse the array.

1 Like

If you mean to swap out the add node for a subtract node, I tried that but the button just gets stuck on the player’s camera and displays it at a weird angle for some reason.



1 Like

Here is an example:

Moving right

Moving left

Edit: correct image.

Toggle buttons

Result:

wrapingIndex

1 Like

Apologies for the confusion I have never used indexes before. So I understand how to set up the math formula but I don’t know where you get the “active/not active” buttons from, or what the “W Icon” is supposed to be. I am also setting my buttons up directly in the events so the setup difference is also somewhat throwing me off, sorry.

EDIT: Oh, wait, I think it’s working? I fiddled around with the math nodes and tried just attaching the expression to the length instead using nodes to perform the operations manually, and it seems to be working as intended now. Thanks to the both of you!

1 Like

For what its worth here is the project I did to record the gif above.

WrapIndex.zip (67.0 KB)

1 Like