It's not an error? For some reason it tells me the array is too small

Question:For some treason it tells me the aray is to small.
“Unhandled exception. System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Program.ceackforablock(Boolean[,] inputaray) in /home/runner/ticktactoe/main.cs:line 37
at Program.Main(String[] args) in /home/runner/ticktactoe/main.cs:line 9”



Repl link:https://replit.com/@Josephyc/ticktactoe


    public static void Main(string[] args)
    {
        Console.WriteLine("Hello World");
        bool[,] ticktactoebourd = {{true,true,false},{true,true,false},{true,true,false}};
        ceackforablock(ticktactoebourd);
    }
    static public bool ceackforablock(bool[,] inputaray)
    {
        bool[,] isblockedaray = { { false, false, false }, { false, false, false }, { false, false, false } };
        bool isbloked = false;
        int x = -1;
        int y =  0;
        int isthisthefirstone = 0;
        if (isthisthefirstone == 0)
        {
            foreach (bool input in inputaray)
            {
                bool isyesinputturn = false;
                if (x == 2)
                {
                    y++;
                    x = -1;
                }
                if (x > 3)
                {
                    x++;
                }
                if(y == 3){
                  y=0;
                }
                if (input)
                {
                    isblockedaray[x, y] = true;
                    isyesinputturn = true;
                }
                if (!(input) && (isyesinputturn = false))
                {
                    isblockedaray[x, y] = false;
                    isyesinputturn = false;
                }
                isyesinputturn = false;
            }
        }
      if (isthisthefirstone > 0)
        {
            foreach (bool input2 in inputaray)
            {
                if (x == 2)
                {
                    y++;
                    x = -1;
                }
                if (x > 3)
                {
                    x++;
                }
                if(y == 2){
                  y=0;
                }
              if (input2 == true && isblockedaray[x, y] == true)
                {
                    return isbloked = true;

                }
              if ((input2 == false && isblockedaray[x, y] == true) || (input2 == true && isblockedaray[x, y] == false))
                {
                    return isbloked = false;
                  
                }
            }
        }
      return isbloked;
    }

It is easier for us to help if you provide the actual error message.

@Firepup650
there you go

You didn’t put anything useful in your post. Did it fail to paste?

They put it in the original post for some reason :person_shrugging:

I’m not sure (as I don’t use C#), but it seems like you are trying to read data outside of the array’s bounds. Why don’t you add this above if (input) so we can see what x and y are per-loop:

Console.WriteLine(x);
Console.WriteLine(y);

what do you mean by that???

What do you mean what do I mean?

i dont know what you said

Can you explain what part of what I said that you did not understand?

yo you what me to add a if statmaent to cheack how many things are in the virable?
@Firepup650

I want you to add temporary WriteLine commands so we can see what the values of those variables are prior to the error.

1 Like

okay
going to do that

it gives me -1 and 0

-1 is out of bounds for arrays, that could be your error.

@Firepup650
ive done that

I saw, and I responded.

now it just giveing me 1 and 0 not 0 thorugh 2

What did you change? Is it still erroring?

It might be becuase of the set y and x to 0 thing.
it’s not:(