2

I have an arduino project which uses a 2 dimensional array to track row/column info. If I try to assign a row,column pair to a particular element I get an error:

expected primary-expression before '{' token

I can assign individual values without problem but get an error if I try to assign the second array element as an integer pair.

example:
player[0][0] = 1;
player[0][1] = 2;  //this works
//but . . .
player[0] = {1,2};  //doesn't work



//here is more specific code from the project
// …. a bunch of code here declaring various global variables

int players[6][2];  //two dimensional array with 6 players each with a 2 value array (column and row)           
int score1;  //player 1 score
int score2;  //player2 score

//code here for setup/loop/etc.. Code calls the setPlayerPositions() function


void setPlayerPositions() 
{
    players[0] = {2,1};  //set the position of the ball (player[0]) to row 2, column 1
    players[1] = {1,4};  //set other player positions . . .
    players[2] = {2,4};  
    players[3] = {3,4};  
    players[4] = {2,6};  
    players[5] = {2,9};  
}  
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
AGSTEIN
  • 43
  • 2
  • 4

1 Answers1

2

I've beaten my head off the desk with this problem a few times.

Unfortunately, you can only use curly bracket notation when initialising an array. After initialisation you have to work with each array element individually.

Ref: Arduino Cookbook... http://books.google.co.uk/books?id=nxxKNCYXRIwC&lpg=PA31&ots=dH_fWczOAp&pg=PA31#v=onepage

Grant Gibson
  • 793
  • 3
  • 11