Help with error code please

(Mike McRoberts) #1

I have the following code:

Which when I try to compile throws up the following error:

ArduBoy.ino:57:19: error: expected unqualified-id before ‘[’ token

I can’t for the life of me figure out where this error actually is and what is causing it.

Please help !!!



(Gavin Atkin) #2

I believe your error comes from here:
struct gameObjects[0][0] = { 1,24,48,0,0,1,0};

Once an instance of a struct has been declared, I don’t think the compiler will allow this initialization notation.
You could try initializing the values individually using
gameObjects[0][0].type = 1;

Also you are only trying to initialize one game objects variables, but in your loop you are checking the values of every index. The values need to all be initialized before checked.

(Mike McRoberts) #3

If I remove the struct before the lien then the error changes to:

ArduBoy.ino:57:1: error: ‘gameObjects’ does not name a type

I changed the array to [1][1] and it still says the same

(Mike McRoberts) #5

Changed it to:

struct objects gameObjects[1][1];

struct gameObjects[0][0] = {

Still getting same error.

(Gavin Atkin) #6

You could try a double loop to initialize everything.
for (byte i = 0; i < 2; i++) {
for (byte j = 0; j < 10; j++) {
gameObject[i][j].type = 1;
gameObject[i][j].x = 24;

gameObject[i][j].state = 0;

*The spaces get removed when I post. Add proper indentation and the remaining variables of the struct.

(Scott) #7

Sorry, my previous answer was incorrect. You can only pre-initialise the array at the time that you define it. Otherwise, you have to set its values from within the code.

struct objects
 byte type;
 byte x;
 byte y;
 float xRate;
 float yRate;
 boolean direction;
 byte state;
} ;
struct objects gameObjects[2][10];

void setup() {
  gameObjects[0][0] = { 1,24,48,0,0,1,0};

void loop() {

(Mike McRoberts) #8


That did the trick. No more error code.

Thank you very much Scott.