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};  
}  
1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that was what I was afraid of, just couldn't find it stated explicitly in anywhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.