'function was not declared in this scope' error help?

This is the program (work in progress):

byte RPS[][8] = {

<removed are 8x8 LED matrix controls>

};
#include "LedControl.h"
//#include <Tone.h>
#define DIN 9  //Data  Pin 9
#define CLK 11 //Clock Pin 11
#define CS 10  //Chip Select Pin 10
#define CHIPS 1

const int rockoffenseSwitch = 6;      //Rocko     Pin 6
const int paperoffenseSwitch = 7;     //Papero    Pin 7
const int scissorsoffenseSwitch = 8;  //Scissorso Pin 8


const int rockdefenseSwitch = A0;      //Rockd     Pin analog0
const int paperdefenseSwitch = A1;     //Paperd    Pin analog1
const int scissorsdefenseSwitch = A2;  //Scissorsd Pin analog2

int randomNumber;
int rockoState = 0;
int paperoState = 0;
int scissorsoState = 0;
int rockdState = 0;
int paperdState = 0;
int scissorsdState = 0;
int uor;//Usero Rock
int uop;//Usero Paper
int uos;//Usero Scissors
int udr;//usero Rock
int udp;//userero Paper
int uds;//usero Scissors
LedControl lc = LedControl(DIN, CLK, CS, CHIPS);   //A: idk wtf this is
void setup() 
{
  lc.shutdown(0, false);
  lc.setIntensity(0, 0);
  lc.clearDisplay(0);
  pinMode(rockoffenseSwitch, INPUT);
  pinMode (paperoffenseSwitch, INPUT);
  pinMode (scissorsoffenseSwitch, INPUT);
  pinMode(rockdefenseSwitch, INPUT);
  pinMode (paperdefenseSwitch, INPUT);
  pinMode (scissorsdefenseSwitch, INPUT);
 // randomSeed(analogRead(A0));                  //A: I dont think i need this?
}

void loop() {
uor = 0;
uop = 0;
uos = 0;
udr = 0;
udp = 0;
uds = 0;
challengeDisplay();
rockoState = digitalRead(rockoffenseSwitch);
paperoState = digitalRead(paperoffenseSwitch);
scissorsoState = digitalRead(scissorsoffenseSwitch);
rockdState = digitalRead(rockdefenseSwitch);
paperdState = digitalRead(paperdefenseSwitch);
scissorsdState = digitalRead(scissorsdefenseSwitch);



void challengeDisplay()
{
  // ?
  for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[7][row]);}
  delay (200);
  lc.clearDisplay(0);
}

if (rockoState == HIGH)
// Rock, A: if the rock button is pressed, set rock value to one (now uor/s/p), then make the comptuer choose a number, whichwas removed
  {for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[0][row]);}
  delay (500);
  uor=1;
  lc.clearDisplay(0);
 
  
}

if (paperoState == HIGH)
// Paper
  {for (int row = 0; row < 8; row++) {
    //lc.setRow(0, row, RPS[1][row]);}  
  delay (500); 
  uop=1;
  lc.clearDisplay(0);
 
}
  
  
if (scissorsoState == HIGH)
 // Scissors
  {for (int row = 0; row < 8; row++) {
    //lc.setRow(0, row, RPS[2][row]);}  
  delay (500);
  uos=1; 
  lc.clearDisplay(0);
  
}

if (rockdState == HIGH)
// Rock, A: if the rock button is pressed, set rock value to one (now udr/s/p), then make the comptuer choose a number. which isnt gonna happen anymore
  {for (int row = 0; row < 8; row++) {
    //lc.setRow(0, row, RPS[0][row]);}
  delay (500);
  udr=1;
  lc.clearDisplay(0);
 
  
}

if (paperdState == HIGH)
// Paper
  {for (int row = 0; row < 8; row++) {
    //lc.setRow(0, row, RPS[1][row]);}  
  delay (500); 
  udp=1;
  lc.clearDisplay(0);
 
}
  
  
if (scissorsdState == HIGH)
 // Scissors
  {for (int row = 0; row < 8; row++) {
    //lc.setRow(0, row, RPS[2][row]);}  
  delay (500);
  uds=1; 
  lc.clearDisplay(0);
  
}
}



void dWins()   //A: this is what happens when computer wins, change to defense?
{
  delay (400);
  // C  
  {for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[8][row]);}
  delay (500);
  lc.clearDisplay(0);
  // W display
  for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[13][row]);}  
  delay (500); 
  lc.clearDisplay(0);
  delay(1000);  
  // 1st loop
  for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[9][row]);}  
  delay (200); 
  lc.clearDisplay(0);
  // 2nd loop
  for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[10][row]);}  
  delay (200); 
  lc.clearDisplay(0);
  // 3rd loop
  for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[11][row]);}  
  delay (200); 
  lc.clearDisplay(0);
 //  4th loop
  for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[12][row]);}  
  delay (200); 
  lc.clearDisplay(0);
  delay (400);
  {for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[8][row]);} //c
  delay (500);
  lc.clearDisplay(0);
  // W display
  for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[13][row]);}  
  delay (500); 
  lc.clearDisplay(0);
  delay(1000); 
  } 
  }  
}

void oWins()     //this is what happens when user wins, leads change to offense
{
  delay (400);
  // U
  {for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[14][row]);}  
  delay (500); 
  lc.clearDisplay(0);
  // W display
  for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[13][row]);}  
  delay (500); 
  lc.clearDisplay(0);
  delay(1000);
  // 1st loop
  for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[9][row]);}  
  delay (200); 
  lc.clearDisplay(0);
   // 2nd loop
  for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[10][row]);}  
  delay (200); 
  lc.clearDisplay(0);
  // 3rd loop
  for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[11][row]);}  
  delay (200); 
  lc.clearDisplay(0);
 //  4th loop
 for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[12][row]);}  
  delay (200); 
  lc.clearDisplay(0);
  delay (400);
  // U
  {for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[14][row]);}  
  delay (500); 
  lc.clearDisplay(0);
  // W display
  for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[13][row]);}  
  delay (500); 
  lc.clearDisplay(0);
  delay(1000);
}
}
}
void computerchooses(){
  
//randomNumber = random(1,4); //A: this is unneeded now, since 2  ppl
//cr = 0;
//cp = 0;
//cs = 0;

switch (randomNumber) {

case 1: 
  delay (200);
  for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[8][row]);}
  delay (500);
  lc.clearDisplay(0);
  
  // Rock
  {for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[0][row]);}
  delay (500);
  udr=1;
  lc.clearDisplay(0);}

  if (udr==uor)
  //Tie
  {for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[3][row]);}  
  delay (1000); 
  lc.clearDisplay(0);}
  
  if (udr==uop)
  //Paper covers Rock
  {for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[4][row]);}  
  delay (1000); 
  lc.clearDisplay(0);
  oWins();
 }
  if (udr==uos)
  //Rock smashes Scissors
  {for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[6][row]);}  
  delay (1000); 
  lc.clearDisplay(0);  
  dWins();}
  
break;

case 2: 
  delay (200);
  for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[8][row]);}
  delay (500);
  lc.clearDisplay(0);
  
  // Paper
  {for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[1][row]);}  
  delay (500); 
  udp=1;
  lc.clearDisplay(0);}
  
  //Tie
  if (uop==udp)
  {for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[3][row]);}  
  delay (1000); 
  lc.clearDisplay(0);}  

  if (udp==uos)
  //Scissors cuts Paper
  {for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[5][row]);}  
  delay (1000); 
  lc.clearDisplay(0); 
  oWins();}
  
  if (udp==uor)
  {for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[4][row]);}  
  delay (1000); 
  lc.clearDisplay(0);
  dWins();}
  
break;

case 3:

  delay (200);
  for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[8][row]);}
  delay (500);
  lc.clearDisplay(0);
  
  // Scissors
  {for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[2][row]);}  
  delay (500);
  uds=1; 
  lc.clearDisplay(0);}
  
  //Tie
  if (uos==uds)
  {for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[3][row]);}  
  delay (1000); 
  lc.clearDisplay(0);}

  //Rock smashes Scissors
  if (uds==uor)
  { for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[6][row]);}  
  delay (1000); 
  lc.clearDisplay(0);  
  oWins();}
  
  //Scissors cuts Paper
  if (uds==uop)
  {for (int row = 0; row < 8; row++) {
    lc.setRow(0, row, RPS[5][row]);}  
  delay (1000); 
  lc.clearDisplay(0);  
  dWins();}
  
break;  
  
}
}

And when I compile, I get the error “‘challengeDisplay’ was not declared in this scope” Does anyone know why this happens and how to fix it?

Where does the loop function end? Right now challengeDisplay is defined inside of loop. That's not good. Check your braces. Do an auto-format on the code and problems like that will be apparent from the indenting. We don't format code the way we do just to make it pretty.

Hi,
I have taken your code and put ALL { and } brackets on thier own line.
Then executed an “Auto-Format” which is CTRL-T, or under the TOOLS tab

This indents you code so you can see you code loops.
I’m not sure if this is code you have written or editing from an example.

void setup()
{
  lc.shutdown(0, false);
  lc.setIntensity(0, 0);
  lc.clearDisplay(0);
  pinMode(rockoffenseSwitch, INPUT);
  pinMode (paperoffenseSwitch, INPUT);
  pinMode (scissorsoffenseSwitch, INPUT);
  pinMode(rockdefenseSwitch, INPUT);
  pinMode (paperdefenseSwitch, INPUT);
  pinMode (scissorsdefenseSwitch, INPUT);
  // randomSeed(analogRead(A0));                  //A: I dont think i need this?
}
void loop()
{
  uor = 0;
  uop = 0;
  uos = 0;
  udr = 0;
  udp = 0;
  uds = 0;
  challengeDisplay();
  rockoState = digitalRead(rockoffenseSwitch);
  paperoState = digitalRead(paperoffenseSwitch);
  scissorsoState = digitalRead(scissorsoffenseSwitch);
  rockdState = digitalRead(rockdefenseSwitch);
  paperdState = digitalRead(paperdefenseSwitch);
  scissorsdState = digitalRead(scissorsdefenseSwitch);

  void challengeDisplay()
  {
    // ?
    for (int row = 0; row < 8; row++)
    {
      lc.setRow(0, row, RPS[7][row]);
    }
    delay (200);
    lc.clearDisplay(0);
  }
  if (rockoState == HIGH)
    // Rock, A: if the rock button is pressed, set rock value to one (now uor/s/p), then make the comptuer choose a number, whichwas removed
  {
    for (int row = 0; row < 8; row++)
    {
    }
    lc.setRow(0, row, RPS[0][row]);
  }
  delay (500);
  uor = 1;
  lc.clearDisplay(0);
}
if (paperoState == HIGH)
  // Paper
{
  for (int row = 0; row < 8; row++)
  {
  }
  //lc.setRow(0, row, RPS[1][row]);}
  delay (500);
  uop = 1;
  lc.clearDisplay(0);
}
if (scissorsoState == HIGH)
  // Scissors
{
  for (int row = 0; row < 8; row++)
  {
  }
  //lc.setRow(0, row, RPS[2][row]);}
  delay (500);
  uos = 1;
  lc.clearDisplay(0);
}
if (rockdState == HIGH)
  // Rock, A: if the rock button is pressed, set rock value to one (now udr/s/p), then make the comptuer choose a number. which isnt gonna happen anymore
{
  for (int row = 0; row < 8; row++)
  {
  }
  //lc.setRow(0, row, RPS[0][row]);}
  delay (500);
  udr = 1;
  lc.clearDisplay(0);
}
if (paperdState == HIGH)
  // Paper
{
  for (int row = 0; row < 8; row++)
  {
  }
  //lc.setRow(0, row, RPS[1][row]);}
  delay (500);
  udp = 1;
  lc.clearDisplay(0);
}
if (scissorsdState == HIGH)
  // Scissors
{
  for (int row = 0; row < 8; row++)
  {
    //lc.setRow(0, row, RPS[2][row]);}
    delay (500);
    uds = 1;
    lc.clearDisplay(0);

  }
}

I have only edited part of your code, but as you can you have many { } pairs that do nothing as well as missing brackets.

Tom… :slight_smile:

This is a case of where the first error is not the root cause. In this case a function was not declared properly so the Arduino IDE didn't generate a prototype for it. When the compiler comes across a use of a function for which it has not seen a a declaration (or prototype/forward declaration) it will emit that error. The root problem was not properly closing the loop() function. There would be an error message for that further down in the error messages.