Understanding the language, error messages, etc.
Post a reply

too many initializers error

Sun Jul 27, 2014 1:33 pm

why this works:

Code:
const byte PROGMEM invader[][8] = {
  {5,3, B11011,B11111,B01010},
  {5,3, B01110,B11111,B11011},
  {5,3, B01110,B11111,B01010},
  {5,3, B01010,B11111,B10101},
  {5,3, B01010,B01110,B00100},
  {5,3, B00100,B01110,B01010},
  {5,3, B10101,B01010,B10101},
  {5,3, B01010,B10001,B01010},
};


But this doesn't:

Code:
const byte PROGMEM playership[][3] = {
  {5,3, B00100,B11111,B11111},
  {5,3, B00100,B01010,B10101},
  {5,3, B00000,B10101,B01010},
};


The last one creates an - too many initializers for 'const byte[3]' - error.

Re: too many initializers error

Sun Jul 27, 2014 1:49 pm

The number in the second [] should be the length of the inner arrays, not the number of them, in this case 5.

Re: too many initializers error

Sun Jul 27, 2014 3:16 pm

Ah, I see!

Then, how do I display the three different images?

This doesn't seem to work:

Code:
     
gb.display.drawBitmap(x,y,playership[0]); // show 1st frame
gb.display.drawBitmap(x,y,playership[1]); // show 2nd frame

Re: too many initializers error

Sun Jul 27, 2014 4:21 pm

The numbers after the 'B's are 1 byte (8 bits) long, the ones you have are only 5 long, the compiler is filling in the three missing digits on the left with 0s, but the draw bitmap function read the first 5 digits, effectively shifting your image right and cutting it off. To fix this you can put three 1s (or 0s)on the right end of each byte e.g.
Code:
const byte PROGMEM playership[][5] = {
  {5,3, B00100111,B11111111,B11111111},
  {5,3, B00100111,B01010111,B10101111},
  {5,3, B00000111,B10101111,B01010111},
};


That seems to be working for me.
Post a reply