So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Weberet
#82164 Hi all,

How do you properly declare a 2D array and access it on the NodeMCU?

I've been searching high and low for how to properly declare a nested table / 2D array using eLua on the NodeMCU that I am using and have tried many different combinations of declaring and filling it. I've looked for the documentation on common things such as this and have been unable to find a consistent answer. Does anyone know how this might be accomplished? (Current code included below.)

Code: Select all//Color Array Setup
int ColorRed[]= {255, 0, 0}; //Red
int ColorOrange[]= {255, 127, 0}; //Orange
int ColorYellow[]= {255, 255, 0}; //Yellow
int ColorGreen[]= {0, 255, 0}; //Green
int ColorBlue[]= {0, 0, 255}; //Blue
int ColorIndigo[]= {75, 0, 130}; //Indigo
int ColorViolet[]= {148, 0, 211}; //Violet
int ColorWhite[]= {255, 255, 255}; //White

//Various Attempts:
//used to be static const int*
//int* ColorsArray[1][3]={{ColorRed}, {ColorOrange}, {ColorYellow}, {ColorGreen}, {ColorBlue}, {ColorIndigo}, {ColorViolet}, {ColorWhite}};
//{ColorRed[]},{255, 127, 0},{255, 255, 0},{0, 255, 0},{0, 0, 255},{75, 0, 130},{148, 0, 211},{148, 0, 211},{255, 255, 255}

//Current attempt:
int ColorsArray[][3] = {{ColorRed},{ColorOrange},{ColorYellow},{ColorGreen},{ColorBlue},{ColorIndigo},{ColorViolet},{ColorWhite}};


Whenever I do this it typically throws an error about converting int* to int and other such various errors.

Any help would be appreciated, thank you!
(I want to be able to access via something like ColorRedRedValue = ColorsArray[1][1] which would yield 255)