Mega Man-style weapon hot swap

I want to be able to switch weapons on the fly in the same way as in the Mega Man X series and Mega Man 7. Pressing L and R cycles back and forth between obtained weapons but skips over unobtained ones.

I would try it using two scene variables: a number variable to keep track of which weapon is selected, and an array variable to keep track of all the obtained weapons.

Every time a new weapon is obtained, you can set the value of the array variable to “obtained”

Then, when the player presses a key to move either forward or backward through the weapon, you can add +1 or -1 to the number variable to select a different weapon. You can check if the weapon is obtained, and if not you can do another +1 or -1 instead.

You can use the repeat until true loop to keep looping through the array until it lands on a weapon that is obtained.

Thanks. I’d also like a code example.