Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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};  
}  
share|improve this question

1 Answer 1

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

share|improve this answer
    
Thanks, that was what I was afraid of, just couldn't find it stated explicitly in anywhere. –  AGSTEIN Mar 10 at 2:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.