"incompatible types in assignment of 'int' to 'int [8]'" error

Hello,
When attempting to compile code I'm met with this error (shown below) and I'm unsure on how to fix it. I'm generally quite new to arduino and have only done a couple of projects so am also open to criticism.

Here is the error:

error: incompatible types in assignment of 'int' to 'int [8]'
neighbourArray[targetY, targetX] = total;
___________________________________________ ^~~~~
exit status 1
Compilation error: incompatible types in assignment of 'int' to 'int [8]'

Here is the code in question:

void loop() {
  int rowNum = 8;
  int columnNum = 8;
  bool cellArray[][8] = {
    { false, true, false, false, false, false, false, false },
    { false, false, false, false, false, false, false, false },
    { false, false, false, false, false, false, false, false },
    { false, false, false, false, false, false, false, false },
    { false, false, false, false, false, false, false, false },
    { false, false, false, false, false, false, false, false },
    { false, false, false, false, false, false, false, false },
    { false, false, false, false, false, false, false, false }
  };

  int neighbourArray[][8] = {
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0 },
    { 0, 0, 0, 0, 0, 0, 0, 0 }
  };

  int Gloop = 0;
  while (Gloop == 0) {
    int total;
    for (int targetY = 0; targetY < rowNum; targetY++) {
      for (int targetX = 0; targetX < columnNum; targetX++) {
        total = 0;
        for (int neighbourY = targetY - 1; neighbourY < targetY + 2; neighbourY++) {
          for (int neighbourX = targetX - 1; neighbourX < targetX + 2; neighbourX++) {
            if (neighbourY < rowNum & neighbourX < columnNum & neighbourY >= 0 & neighbourX >= 0) {
              total += cellArray[neighbourY, neighbourX];
            }
          }
        }
        if (cellArray[targetY, targetX] == true) {
          neighbourArray[targetY, targetX] = total - 1;
        } else {
          neighbourArray[targetY, targetX] = total;
        }
      }
    }
  }
}

This section of code should work completley seperatley from the main program as it uses seperate and new variables compared to the rest of the program, so i have taken it out (the error still occurs here)
I am using true and false for "cellArray" because the dot matrix and the library im using needs it to be able to work.

Thank you :slight_smile:

Please show a full sketch that we can try.

In the "Preferences" set the Compiler Warnings to "All". The error that you mention is the last one, but it is better to start with the first problem that the compiler encounters.

its a mess but ok

Was that supposed to be neighbourArray[targetY][targetX]

1 Like

thank you lol, i feel like an idiot :sweat_smile: :rofl:

Was this:

if (neighbourY < rowNum & neighbourX < columnNum & neighbourY >= 0 & neighbourX >= 0) {

Supposed to be this:

if (neighbourY < rowNum && neighbourX < columnNum && neighbourY >= 0 && neighbourX >= 0) {

You can use the words 'and' and 'or':

if (neighbourY < rowNum and neighbourX < columnNum and neighbourY >= 0 and neighbourX >= 0) {

The total is counted with 'true' and 'false'. I prefer that you translate the 'true' and 'false' to '1' and '0'.
Your code:

total += cellArray[neighbourY][neighbourX];

Better code:

if( cellArray[neighbourY][neighbourX])   // test the condition for true or false
  total++;

Oops, I quickly changed the "," to "][" . Thanks SemperIdem

I think we've already agreed otherwise

Hi,
thank you,
didnt see any of that, would have probably broken at some point and hopefully would've realised!
Made the changes to the main program and gonna test it on the arduinoo now.

lol,

thank you for the help!!

int sensitivity = EEPROM.read(0

EEPROM.read() returns a single byte
An int has 2 bytes

Can you see a problem ?

yea, didnt realise, im rlly lazy lol
the one below rlly should be a byte as it only ever uses 0 or 1

actually both should be byte's as they will never get to high enough numbers to use 2 bytes woth of data

yes i know this code is a trainwreck aswell

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.