#Array out of bounds
1 messages · Page 1 of 1 (latest)
yes
Different error ;)
But honestly, you could try add it everywehree
but it will never solve your issue
it will just not work
You gotta think about why you were getting the error in the first place
Your code was mostly correct, just missed a crucial step
yeah i really dont wanna say i give up but its really frustrating 😅
It's all good man, you can do this
ill try
So you know how you just wildly access the reelsRenderer array?
And that somehow seems to work
yes
Do you set them from the editor by any chance?
yes i do
Did you do that for reelsSpinning?
i did that for basically every reels object
Just print out reelsSpining.length in your update, or any function for that matter
ok so im dumb i had it set to 4 instead of 24
buuuut it doesnt change anything xd
it still says that line 133 is the troublemaker
but im guessing its some other underlying issue
You had reelssprinning set to have a length of 4?
yes xd
alright
but somehow all the reels were spinning before
You can also set it from code by the way, so you don't have to change it in two locations everytime you add a new reel
bool[] switches = new bool[20];
And then use the length of your reelsRenderer instead of setting it to a hardcoded 24 ;)
smart
this what you had in mind?
ima take a short 10 min break
thank you for helping me btw
Exactly
Might be frustrating but I have a feeling you learned something new, so next time you run into a similar issue youll probably solve it in <10 minutes
i certainly hope so 😅
so you said even if i use if clauses to detect if there were still any reels left that wouldnt fix the problem right?
well that sounds about right but i still need them,right? So the question is what do i write in addition in the if clause
Having those if clauses can actually be bad, because if you do have an error, such as going out of bounds you wont see it
oh okay
But you still expect that the property is set to false right
So in another part of the code, you start scratching your head, why is this not false
You should only write those checks if you expect it to sometimes be false
so realistically, you assume that reelsSpinning has a boolean for every reelRenderer right? So when that suddenly isn't the case something is very very wrong
but i want the reels to stop at some point,no?
yes you do
this has nothing to do with the functionality of your code
just the way you can solve problems with it
you don't have to add checks for everything everywhere
is what im trying to say
but the amount of sprite renderers and reelsSpinning elements are the same
oh wait
it still doesnt make sense to me xd
the SpriteRenderer doesnt get deleted right?
and the boolean index values just get changed
im running it through my head and it doesnt click
The code you are currently writing can be fairly hard to follow
Since you are working with coroutines
yeah ive had a friend who knows c# better than me help me with this
Gotcha
so does this error even affect the functionality of the app as is?
Happens to me all the time, where I can no logner follow what is going on, here's what I usually do to make it easier for my self:
- Format the code to reduce eye strain,
- Write explaining what methods / blocks do,
- Simplify code
i thought it would be an issue if i tried to spin it again but it seems to work
I dont know what your error is
And I also don't have an updated version of your code right now
wait you dont know either?
so the code should normally be fine?
i feel like im going insane
No im saying that you haven't provided me with an update
and I don't have access to your computer
line numbers move around whenever you edit code
so you saying; I have an error on line 133
is like me saying hey man I have this error in player.cs on line 53
all good
now its 139 bc i put a br there
when i surrounded that in my if clause it pointed to 102
and the common trope is the reelIndex which we already know is going haywire
So lets focus on it one error at a time
Adding if statements around a function like this is a blanket fix
You'll just be playing whack-a-mole with the bugs
An easy way to get some information is to just log the values before the offending statement
So just adding Debug.Log($"reelIndex: {reelIndex}, nextFrame {nextFrame}") could give you some informaiton
debugging
I don't think reelIndex should go out of bounds here
yeah im not that familiar with debugging where should i type that?
Debugging is one of the most important skills you could learn
Debug.log just prints something out to the unity console
This function, although not the best way to debug problems, can be very helpful in giving you insight on what the program state is just before it crashes
ok so i get it now i think. after the index goes above 23 it should be reset to 0 and the rest should be added
no?
and that for every instance with reelIndex
So reelindex is going above 23?
Now you gotta figure out why that's the case
So you follow the call stack up -> stopReel -> SpinReel -> Spin() and you see that there reelIndex gets passed as i
and where does i get its value from?
Should I keep checking this thread or did you solve your problem? @cerulean plinth