❔ System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'
Why cant i use the int mainStory inside my array?
System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'
Im making a text based story adventure and i wanted to be able to control the output with one line of code and adding mainStory++ so when it loops round it plays the next line of the story.
c# doesnt want to let me. the picture should clear it up for you.
Thanks Tom3 Replies
you can use
mainStory
just fine
the actual question is what's the value of mainStory
and LevelOne
arrays have a set length
if you try to access them with an index outside of that length, you get that exception
mainStory is probably increasing every time that while loop happens
and you don't check if it's within LevelOne
using a
foreach
loop over arrays avoids this issueWas this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.