#Array out of bounds

1 messages · Page 1 of 1 (latest)

vivid pelican
#

okay do you still run into the same error?

cerulean plinth
#

yes

vivid pelican
#

Exactly the same?

#

Or on a different line

cerulean plinth
#

oh wait yeah

#

now its line 133

#

i just assumed it was the same mb

vivid pelican
#

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

cerulean plinth
#

yeah i really dont wanna say i give up but its really frustrating 😅

vivid pelican
#

It's all good man, you can do this

cerulean plinth
#

ill try

vivid pelican
#

So you know how you just wildly access the reelsRenderer array?

#

And that somehow seems to work

cerulean plinth
#

yes

vivid pelican
#

Do you set them from the editor by any chance?

cerulean plinth
#

yes i do

vivid pelican
#

Did you do that for reelsSpinning?

cerulean plinth
#

i did that for basically every reels object

vivid pelican
#

Just print out reelsSpining.length in your update, or any function for that matter

cerulean plinth
#

oooh

#

wait

vivid pelican
#

Yes, did you also that for reelsSpinning?

#

😄

cerulean plinth
#

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

vivid pelican
#

You had reelssprinning set to have a length of 4?

cerulean plinth
#

yes xd

vivid pelican
#

alright

cerulean plinth
#

but somehow all the reels were spinning before

vivid pelican
#

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 ;)

cerulean plinth
#

smart

#

this what you had in mind?

#

ima take a short 10 min break

#

thank you for helping me btw

vivid pelican
#

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

cerulean plinth
#

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

vivid pelican
#

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

cerulean plinth
#

oh okay

vivid pelican
#

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

cerulean plinth
#

but i want the reels to stop at some point,no?

vivid pelican
#

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

cerulean plinth
#

but the amount of sprite renderers and reelsSpinning elements are the same

vivid pelican
#

Exactly

#

So if they aren'

#

aren't, it should crash

cerulean plinth
#

oh wait

#

it still doesnt make sense to me xd
the SpriteRenderer doesnt get deleted right?

vivid pelican
#

It doesn't

#

Are you still running into rpoblems?

cerulean plinth
#

and the boolean index values just get changed

#

im running it through my head and it doesnt click

vivid pelican
#

The code you are currently writing can be fairly hard to follow

#

Since you are working with coroutines

cerulean plinth
#

yeah ive had a friend who knows c# better than me help me with this

vivid pelican
#

Gotcha

cerulean plinth
#

so does this error even affect the functionality of the app as is?

vivid pelican
#

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
cerulean plinth
#

i thought it would be an issue if i tried to spin it again but it seems to work

vivid pelican
#

I dont know what your error is

#

And I also don't have an updated version of your code right now

cerulean plinth
#

wait you dont know either?

#

so the code should normally be fine?

#

i feel like im going insane

vivid pelican
#

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

cerulean plinth
#

oh

#

mb xd

vivid pelican
#

all good

cerulean plinth
#

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

vivid pelican
#

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

cerulean plinth
#

debugging

vivid pelican
#

I don't think reelIndex should go out of bounds here

cerulean plinth
#

yeah im not that familiar with debugging where should i type that?

vivid pelican
#

Debugging is one of the most important skills you could learn

#

Debug.log just prints something out to the unity console

cerulean plinth
#

ok i just gotta figure out how i can type in the console

#

oh nvm im dumb

vivid pelican
#

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

cerulean plinth
#

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

vivid pelican
#

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?

vivid pelican
#

Should I keep checking this thread or did you solve your problem? @cerulean plinth

cerulean plinth
#

Pls stay with me im taking a break for family and friends

#

Thanks alot for the help up until now i feel like ive learned a bunch of new things