Quantcast
Channel: Questions in topic: "exception"
Viewing all articles
Browse latest Browse all 470

"Array out of range" when cycling weapons.

$
0
0
I'm using the mousewheel to cycle through an array of 3 (so far) weapons. on mousewheel up it cycles up through the list, and on mousewheel down it counts down. This works fine, and prints the weapon currently selected to the terminal. However, if weapon 3 is selected and the mousewheel pushed up, it throws an exception, "array out of range." Now obviously that's because the variable has increased to 4 and there are only 3 objects in the array, but I can't figure a way to stop it. Putting the following in my update phase doesn't work: if (weaponNumber < 0) { weaponNumber = weapons.Length; } if (weaponNumber > weapons.Length) { weaponNumber = 0; } I've searched around but can't find a solution. I'm sure it's something really simple I'm missing. Thanks

Viewing all articles
Browse latest Browse all 470

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>