resetDartsFired not declared in this scope

Hello, I am currently trying to build a code, and when compiling, I receive this error message

Here is the code

static int LASTSW;
  int SWREAD = whatSW();

  if (SWREAD != LASTSW){
    // DOSOMETHING
    if (SWREAD == 1){}
    if (SWREAD == 2){}
    if (SWREAD == 3){}
    if (SWREAD == 4){}
    LASTSW =  SWREAD;    
  }
}
int whatSW(){
  if(digitalRead(sw1_Pin)){return 1;}
  if(digitalRead(sw2_Pin)){return 2;}
  if(digitalRead(sw3_Pin)){return 3;}
  if(digitalRead(sw4_Pin)){return 4;}
  return 0;
}
Arduino: 1.8.12 (Mac OS X), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

/Users/andrew2607/Desktop/nerf-select-fire_custom/nerf-select-fire_custom.ino: In function 'void setup()':
nerf-select-fire_custom:49:3: error: 'resetDartsFired' was not declared in this scope
   resetDartsFired();                           //reset all dart firing values so they dont get messed up later
   ^~~~~~~~~~~~~~~
/Users/andrew2607/Desktop/nerf-select-fire_custom/nerf-select-fire_custom.ino:49:3: note: suggested alternative: 'dartsFired'
   resetDartsFired();                           //reset all dart firing values so they dont get messed up later
   ^~~~~~~~~~~~~~~
   dartsFired
/Users/andrew2607/Desktop/nerf-select-fire_custom/nerf-select-fire_custom.ino: In function 'void loop()':
nerf-select-fire_custom:53:3: error: 'toggleFireModes' was not declared in this scope
   toggleFireModes();                          //constantly check for changes in firemodes
   ^~~~~~~~~~~~~~~
nerf-select-fire_custom:54:3: error: 'fire' was not declared in this scope
   fire();                                //constantly check if dart is fired
   ^~~~
/Users/andrew2607/Desktop/nerf-select-fire_custom/nerf-select-fire_custom.ino:54:3: note: suggested alternative: 'free'
   fire();                                //constantly check if dart is fired
   ^~~~
   free
nerf-select-fire_custom:55:3: error: 'checkForDartsFired' was not declared in this scope
   checkForDartsFired();                         //do stuff if dart is fired
   ^~~~~~~~~~~~~~~~~~
/Users/andrew2607/Desktop/nerf-select-fire_custom/nerf-select-fire_custom.ino:55:3: note: suggested alternative: 'isCheckingForDartsFired'
   checkForDartsFired();                         //do stuff if dart is fired
   ^~~~~~~~~~~~~~~~~~
   isCheckingForDartsFired
nerf-select-fire_custom:56:3: error: 'selectFire' was not declared in this scope
   selectFire();                             //do fancy select-fire stuff
   ^~~~~~~~~~
nerf-select-fire_custom:63:7: error: 'firemode' was not declared in this scope
       firemode == SAFETY
       ^~~~~~~~
/Users/andrew2607/Desktop/nerf-select-fire_custom/nerf-select-fire_custom.ino:63:7: note: suggested alternative: 'fireMode'
       firemode == SAFETY
       ^~~~~~~~
       fireMode
nerf-select-fire_custom:66:7: error: 'firemode' was not declared in this scope
       firemode == SINGLE_FIRE
       ^~~~~~~~
/Users/andrew2607/Desktop/nerf-select-fire_custom/nerf-select-fire_custom.ino:66:7: note: suggested alternative: 'fireMode'
       firemode == SINGLE_FIRE
       ^~~~~~~~
       fireMode
nerf-select-fire_custom:69:7: error: 'firemode' was not declared in this scope
       firemode == BURST_FIRE
       ^~~~~~~~
/Users/andrew2607/Desktop/nerf-select-fire_custom/nerf-select-fire_custom.ino:69:7: note: suggested alternative: 'fireMode'
       firemode == BURST_FIRE
       ^~~~~~~~
       fireMode
nerf-select-fire_custom:72:7: error: 'firemode' was not declared in this scope
       firemode == FULL_AUTO
       ^~~~~~~~
/Users/andrew2607/Desktop/nerf-select-fire_custom/nerf-select-fire_custom.ino:72:7: note: suggested alternative: 'fireMode'
       firemode == FULL_AUTO
       ^~~~~~~~
       fireMode
nerf-select-fire_custom:75:5: error: 'resetDartsFired' was not declared in this scope
     resetDartsFired();
     ^~~~~~~~~~~~~~~
/Users/andrew2607/Desktop/nerf-select-fire_custom/nerf-select-fire_custom.ino:75:5: note: suggested alternative: 'dartsFired'
     resetDartsFired();
     ^~~~~~~~~~~~~~~
     dartsFired
/Users/andrew2607/Desktop/nerf-select-fire_custom/nerf-select-fire_custom.ino: In function 'int whatSW()':
nerf-select-fire_custom:80:19: error: 'sw1_Pin' was not declared in this scope
   if (digitalRead(sw1_Pin)) {
                   ^~~~~~~
nerf-select-fire_custom:83:19: error: 'sw2_Pin' was not declared in this scope
   if (digitalRead(sw2_Pin)) {
                   ^~~~~~~
nerf-select-fire_custom:86:19: error: 'sw3_Pin' was not declared in this scope
   if (digitalRead(sw3_Pin)) {
                   ^~~~~~~
nerf-select-fire_custom:89:19: error: 'sw4_Pin' was not declared in this scope
   if (digitalRead(sw4_Pin)) {
                   ^~~~~~~
nerf-select-fire_custom:93:3: error: 'resetDartsFired' was not declared in this scope
   resetDartsFired();
   ^~~~~~~~~~~~~~~
/Users/andrew2607/Desktop/nerf-select-fire_custom/nerf-select-fire_custom.ino:93:3: note: suggested alternative: 'dartsFired'
   resetDartsFired();
   ^~~~~~~~~~~~~~~
   dartsFired
/Users/andrew2607/Desktop/nerf-select-fire_custom/nerf-select-fire_custom.ino: At global scope:
nerf-select-fire_custom:96:1: error: expected declaration before '}' token
 }
 ^
exit status 1
'resetDartsFired' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Here is the code

Post your whole program. Seeing just a snippet is no help at all

whoops, might have got it cut during copying

I dont seem to have it working, I based the code of off github, (GitHub - mochoy/nerf-select-fire: Arduino sketch for select-fire control to full-automatic NERF blasters.). In the original code, the modes were selected from a button press (single button cycle), I want to alter the code to work with rotary switch so the code below is a rough edit that i have made and currently isnt compiling.

/*----------------------------------------------------------------------*
   nerf-select-fire v1.0
   Monty Choy, Nov 2017
 *                                                                      *
   Arduino sketch for saftey, single shot, three round burst, and full
   auto. Schematics can also be found in the repository.
  ----------------------------------------------------------------------*/

#include <JC_Button.h>																											//library to deal with buttons easier

//pins
#define IR_GATE_PIN 0																											//analog input
#define TRIGGER_PIN 11              																			//digital input
#define DART_COUNTER_SWITCH_PIN 4   																			//digital input
#define MOTOR_OUTPUT_PIN 3          																			//digital output
#define ROT_SW_SAFETY_PIN 6                                               //digital output
#define ROT_SW_SEMI_AUTO_PIN 7                                            //digital output
#define ROT_SW_BURST_FIRE_PIN 8                                           //digital output
#define ROT_SW_FULL_AUTO_PIN 9                                            //digital output

#define NUM_OF_ROT_SW_PINS 4
// Array of all rotary switch pins so it's easier to iterate through all of them
const uint8_t ROT_SW_PINS[] = {ROT_SW_SAFETY_PIN, ROT_SW_SEMI_AUTO_PIN, ROT_SW_BURST_FIRE_PIN, ROT_SW_FULL_AUTO_PIN};

//for buttons/switches
#define PULLUP true        																								//internal pullup, so we dont need to wire resistor
#define INVERT true      																									//invert required for proper readings with pullup
#define DEBOUNCE_MS 20 																										//check btn time every 20ms

#define IR_GATE_TRIP 90																										//'trip' value for IR gate					

//code for fire modes. 4 modes total
#define SAFETY 0																													//SAFTEY is mode 0
#define SINGLE_FIRE 1																											//singe fire is mode 1
#define BURST_FIRE 2																											//burst fire is mode 2
#define FULL_AUTO 3																												//full auto is mode 3


byte fireMode = 0;   																											//keep track of fire modes.
byte dartsFired = 0;																											//keep track of how many darts fire
bool isCheckingForDartsFired = false;																			//some modes need to check if a certain number of darts to fire

Button trigger (TRIGGER_PIN, PULLUP, INVERT, DEBOUNCE_MS);														//trigger button, using the library
Button dartCountingSwitch (DART_COUNTER_SWITCH_PIN, PULLUP, INVERT, DEBOUNCE_MS);			//dart counting button, using the library

void setup () {
  pinMode(MOTOR_OUTPUT_PIN, OUTPUT);																		//set motor output pin to an output pin
  digitalWrite(MOTOR_OUTPUT_PIN, LOW);        													//make sure motor is off
  //reset all dart firing values so they dont get messed up later
}

void loop () {
  int SWREAD();																										//constantly check for changes in firemodes
  fire();																																//constantly check if dart is fired
  checkForDartsFired();																									//do stuff if dart is fired
  selectFire();																													//do fancy select-fire stuff

  static int LASTSW;
  int SWREAD = whatSW();

  if (SWREAD != LASTSW) {
    // DOSOMETHING
    if (SWREAD == 1) {
      fireMode == SAFETY
    }
    if (SWREAD == 2) {
      fireMode == SINGLE_FIRE
    }
    if (SWREAD == 3) {
      fireMode == BURST_FIRE
    }
    if (SWREAD == 4) {
      fireMode == FULL_AUTO
    }
    LASTSW =  SWREAD;

  }

}
int whatSW() {
  if (digitalRead(6)) {
    return 1;
  }
  if (digitalRead(7)) {
    return 2;
  }
  if (digitalRead(8)) {
    return 3;
  }
  if (digitalRead(9)) {
    return 4;
  }
  return 0;

}

}

//when dart fired
void fire() {
  dartCountingSwitch.read();																							//read button
  dartsFired += ( (isCheckingForDartsFired && 														//detect and keep track if dart is fired through
                   ( (map(analogRead(IR_GATE_PIN), 0, 1023, 0, 100) > IR_GATE_TRIP) ||		//switch or IR gate.
                     dartCountingSwitch.wasPressed()) )
                  ? 1 : 0);
}

void checkForDartsFired () {
  if (isCheckingForDartsFired && 																					//if checking for darts being fired. Not all
      (fireMode == SINGLE_FIRE || fireMode == BURST_FIRE)) {									// modesneed to check if a dart is fired
    byte dartsToFire = (fireMode == SINGLE_FIRE ? 1 : 3);									//determine max amounts of darts to be fired
    if (dartsFired < dartsToFire) {																				//if can still fire (hasn't reached threshold of
      digitalWrite(MOTOR_OUTPUT_PIN, HIGH);																//how many darts can fire), power pusher motor
    } else if (dartCountingSwitch.isPressed() && 													//if can't fire anymore darts and pusher
               dartsFired >= dartsToFire) {																					//retracted
      resetDartsFired();																									//Reset darts fired stuff so it can happen again
    }
  }
}

//do all the fancy select fire stuff
void selectFire () {
  trigger.read();																												//read trigger
  if (trigger.isPressed()) {      																			//check of trigger is pressed
    if (fireMode == SAFETY) {       																	//if in safety mode, turn off motor
      digitalWrite(MOTOR_OUTPUT_PIN, LOW);
    } else if (fireMode == SINGLE_FIRE || fireMode == BURST_FIRE) {		//if in burst fire or single shot mode
      isCheckingForDartsFired = true;																//allow for darts to be fired, handled elsewhere
    } else if (fireMode == FULL_AUTO) {     													//if full auto turn on motor
      digitalWrite(MOTOR_OUTPUT_PIN, HIGH);
    }
  } else if (!trigger.isPressed()) {    																//if trigger isn't pressed
    if (fireMode == FULL_AUTO || fireMode == SAFETY) {								//if firemode is fullauto or safety, turn off motor
      digitalWrite(MOTOR_OUTPUT_PIN, LOW);
    } else if ( !isCheckingForDartsFired 															//if all darts fired
                && (fireMode == SINGLE_FIRE || fireMode == BURST_FIRE) ) {     	//and in burstfire
      resetDartsFired();																							//reset darts fired stuff
    }
  }
}

void resetDartsFired () {
  digitalWrite(MOTOR_OUTPUT_PIN, LOW);																		//turn of motor
  dartsFired = 0;																													//darts fired set to 0
  isCheckingForDartsFired = false;																				//no longer checking if darts are being fired
}

Auto format your code in the IDE and look closely at where the loop() function ends.

You have an extra closing brace. Putting each brace on its own line is helpful in avoiding this problem

Another problem:

SWREAD is used as both a variable name and a function name. You cannot do this

There maybe more problems so come back when you have fixed these two if you still have problems

after fixing things, i met with this

/*----------------------------------------------------------------------*
   nerf-select-fire v1.0
   Monty Choy, Nov 2017
 *                                                                      *
   Arduino sketch for saftey, single shot, three round burst, and full
   auto. Schematics can also be found in the repository.
  ----------------------------------------------------------------------*/

#include <JC_Button.h>																											//library to deal with buttons easier

//pins
#define IR_GATE_PIN 0																											//analog input
#define TRIGGER_PIN 11              																			//digital input
#define DART_COUNTER_SWITCH_PIN 4   																			//digital input
#define MOTOR_OUTPUT_PIN 3          																			//digital output
#define ROT_SW_SAFETY_PIN 6                                               //digital output
#define ROT_SW_SEMI_AUTO_PIN 7                                            //digital output
#define ROT_SW_BURST_FIRE_PIN 8                                           //digital output
#define ROT_SW_FULL_AUTO_PIN 9                                            //digital output

#define NUM_OF_ROT_SW_PINS 4
// Array of all rotary switch pins so it's easier to iterate through all of them
const uint8_t ROT_SW_PINS[] = {ROT_SW_SAFETY_PIN, ROT_SW_SEMI_AUTO_PIN, ROT_SW_BURST_FIRE_PIN, ROT_SW_FULL_AUTO_PIN};

//for buttons/switches
#define PULLUP true        																								//internal pullup, so we dont need to wire resistor
#define INVERT true      																									//invert required for proper readings with pullup
#define DEBOUNCE_MS 20 																										//check btn time every 20ms

#define IR_GATE_TRIP 90																										//'trip' value for IR gate					

//code for fire modes. 4 modes total
#define SAFETY 0																													//SAFTEY is mode 0
#define SINGLE_FIRE 1																											//singe fire is mode 1
#define BURST_FIRE 2																											//burst fire is mode 2
#define FULL_AUTO 3																												//full auto is mode 3


byte fireMode = 0;   																											//keep track of fire modes.
byte dartsFired = 0;																											//keep track of how many darts fire
bool isCheckingForDartsFired = false;																			//some modes need to check if a certain number of darts to fire

Button trigger (TRIGGER_PIN, PULLUP, INVERT, DEBOUNCE_MS);														//trigger button, using the library
Button dartCountingSwitch (DART_COUNTER_SWITCH_PIN, PULLUP, INVERT, DEBOUNCE_MS);			//dart counting button, using the library

void setup () {
  pinMode(MOTOR_OUTPUT_PIN, OUTPUT);																		//set motor output pin to an output pin
  digitalWrite(MOTOR_OUTPUT_PIN, LOW);        													//make sure motor is off
  //reset all dart firing values so they dont get messed up later
}

void loop () {
  int whatSW();																										//constantly check for changes in firemodes
  fire();																																//constantly check if dart is fired
  checkForDartsFired();																									//do stuff if dart is fired
  selectFire();																													//do fancy select-fire stuff
  resetDartsFired();

  static int LASTSW; {
    int SWREAD = whatSW();

    if (SWREAD != LASTSW) {
      // DOSOMETHING
      if (SWREAD == 1) {
        fireMode == SAFETY;
      }
      if (SWREAD == 2) {
        fireMode == SINGLE_FIRE;
      }
      if (SWREAD == 3) {
        fireMode == BURST_FIRE;
      }
      if (SWREAD == 4) {
        fireMode == FULL_AUTO;
      }
      LASTSW =  SWREAD;
      resetDartsFired();

    }

    int whatSW() {
      if (digitalRead(6)) {
        return 1;
      }
      if (digitalRead(7)) {
        return 2;
      }
      if (digitalRead(8)) {
        return 3;
      }
      if (digitalRead(9)) {
        return 4;
      }
      return 0;

    }
  }

}

//when dart fired
void fire() {
  dartCountingSwitch.read();																							//read button
  dartsFired += ( (isCheckingForDartsFired && 														//detect and keep track if dart is fired through
                   ( (map(analogRead(IR_GATE_PIN), 0, 1023, 0, 100) > IR_GATE_TRIP) ||		//switch or IR gate.
                     dartCountingSwitch.wasPressed()) )
                  ? 1 : 0);
}

void checkForDartsFired () {
  if (isCheckingForDartsFired && 																					//if checking for darts being fired. Not all
      (fireMode == SINGLE_FIRE || fireMode == BURST_FIRE)) {									// modesneed to check if a dart is fired
    byte dartsToFire = (fireMode == SINGLE_FIRE ? 1 : 3);									//determine max amounts of darts to be fired
    if (dartsFired < dartsToFire) {																				//if can still fire (hasn't reached threshold of
      digitalWrite(MOTOR_OUTPUT_PIN, HIGH);																//how many darts can fire), power pusher motor
    } else if (dartCountingSwitch.isPressed() && 													//if can't fire anymore darts and pusher
               dartsFired >= dartsToFire) {																					//retracted
      resetDartsFired();																									//Reset darts fired stuff so it can happen again
    }
  }
}

//do all the fancy select fire stuff
void selectFire () {
  trigger.read();																												//read trigger
  if (trigger.isPressed()) {      																			//check of trigger is pressed
    if (fireMode == SAFETY) {       																	//if in safety mode, turn off motor
      digitalWrite(MOTOR_OUTPUT_PIN, LOW);
    } else if (fireMode == SINGLE_FIRE || fireMode == BURST_FIRE) {		//if in burst fire or single shot mode
      isCheckingForDartsFired = true;																//allow for darts to be fired, handled elsewhere
    } else if (fireMode == FULL_AUTO) {     													//if full auto turn on motor
      digitalWrite(MOTOR_OUTPUT_PIN, HIGH);
    }
  } else if (!trigger.isPressed()) {    																//if trigger isn't pressed
    if (fireMode == FULL_AUTO || fireMode == SAFETY) {								//if firemode is fullauto or safety, turn off motor
      digitalWrite(MOTOR_OUTPUT_PIN, LOW);
    } else if ( !isCheckingForDartsFired 															//if all darts fired
                && (fireMode == SINGLE_FIRE || fireMode == BURST_FIRE) ) {     	//and in burstfire
      resetDartsFired();																							//reset darts fired stuff
    }
  }
}

void resetDartsFired () {
  digitalWrite(MOTOR_OUTPUT_PIN, LOW);																		//turn of motor
  dartsFired = 0;																													//darts fired set to 0
  isCheckingForDartsFired = false;																				//no longer checking if darts are being fired
}
Arduino: 1.8.12 (Mac OS X), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

/Users/andrew2607/Desktop/nerf-select-fire_custom/nerf-select-fire_custom.ino: In function 'void loop()':
nerf-select-fire_custom:81:18: error: a function-definition is not allowed here before '{' token
     int whatSW() {
                  ^
exit status 1
a function-definition is not allowed here before '{' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
        fireMode == FULL_AUTO;
      }
      LASTSW =  SWREAD;
      resetDartsFired();
    }
    int whatSW()
    {
      if (digitalRead(6))
      {
        return 1;

This is part of your latest version Auto formatted in the IDE.

Note how the definition of the whatSW() function is not on the left margin, rather it is actually withing the loop() function code block

You need to carefully check the pairs of braces in your program so that they enclose the proper code blocks. If you click you the right of a brace then the IDE will indicate in the code where the corresponding brace is, if it exists, by putting a box round it

In this case I am guessing that the loop() function should end immediately before the whatSW() function definition and that there is a missing closing brace or braces but look carefully at where the whatSW() function ends

omg im so happy
okay so after re checking every brackets, i have manage to compile succesfully
now how do i check if my program is working with my hardware? any tips on doing so?

/*----------------------------------------------------------------------*
   nerf-select-fire v1.0
   Monty Choy, Nov 2017
 *                                                                      *
   Arduino sketch for saftey, single shot, three round burst, and full
   auto. Schematics can also be found in the repository.
  ----------------------------------------------------------------------*/

#include <JC_Button.h>																											//library to deal with buttons easier

//pins
#define IR_GATE_PIN 0																											//analog input
#define TRIGGER_PIN 11              																			//digital input
#define DART_COUNTER_SWITCH_PIN 4   																			//digital input
#define MOTOR_OUTPUT_PIN 3          																			//digital output
#define ROT_SW_SAFETY_PIN 6                                               //digital output
#define ROT_SW_SEMI_AUTO_PIN 7                                            //digital output
#define ROT_SW_BURST_FIRE_PIN 8                                           //digital output
#define ROT_SW_FULL_AUTO_PIN 9                                            //digital output

#define NUM_OF_ROT_SW_PINS 4
// Array of all rotary switch pins so it's easier to iterate through all of them
const uint8_t ROT_SW_PINS[] = {ROT_SW_SAFETY_PIN, ROT_SW_SEMI_AUTO_PIN, ROT_SW_BURST_FIRE_PIN, ROT_SW_FULL_AUTO_PIN};

//for buttons/switches
#define PULLUP true        																								//internal pullup, so we dont need to wire resistor
#define INVERT true      																									//invert required for proper readings with pullup
#define DEBOUNCE_MS 20 																										//check btn time every 20ms

#define IR_GATE_TRIP 90																										//'trip' value for IR gate					

//code for fire modes. 4 modes total
#define SAFETY 0																													//SAFTEY is mode 0
#define SINGLE_FIRE 1																											//singe fire is mode 1
#define BURST_FIRE 2																											//burst fire is mode 2
#define FULL_AUTO 3																												//full auto is mode 3


byte fireMode = 0;   																											//keep track of fire modes.
byte dartsFired = 0;																											//keep track of how many darts fire
bool isCheckingForDartsFired = false;																			//some modes need to check if a certain number of darts to fire

Button trigger (TRIGGER_PIN, PULLUP, INVERT, DEBOUNCE_MS);														//trigger button, using the library
Button dartCountingSwitch (DART_COUNTER_SWITCH_PIN, PULLUP, INVERT, DEBOUNCE_MS);			//dart counting button, using the library

void setup () {
  pinMode(MOTOR_OUTPUT_PIN, OUTPUT);																		//set motor output pin to an output pin
  digitalWrite(MOTOR_OUTPUT_PIN, LOW);        													//make sure motor is off
  //reset all dart firing values so they dont get messed up later
}

void loop () {
  int whatSW();																										//constantly check for changes in firemodes
  fire();																																//constantly check if dart is fired
  checkForDartsFired();																									//do stuff if dart is fired
  selectFire();																													//do fancy select-fire stuff
  resetDartsFired();

  static int LASTSW; {
    int SWREAD = whatSW();

    if (SWREAD != LASTSW) {
      // DOSOMETHING
      if (SWREAD == 1) {
        fireMode == SAFETY;
      }
      if (SWREAD == 2) {
        fireMode == SINGLE_FIRE;
      }
      if (SWREAD == 3) {
        fireMode == BURST_FIRE;
      }
      if (SWREAD == 4) {
        fireMode == FULL_AUTO;
      }
      LASTSW =  SWREAD;
      resetDartsFired();

    }

  }

}


int whatSW() {
  if (digitalRead(6)) {
    return 1;
  }
  if (digitalRead(7)) {
    return 2;
  }
  if (digitalRead(8)) {
    return 3;
  }
  if (digitalRead(9)) {
    return 4;
  }
  return 0;

}


//when dart fired
void fire() {
  dartCountingSwitch.read();																							//read button
  dartsFired += ( (isCheckingForDartsFired && 														//detect and keep track if dart is fired through
                   ( (map(analogRead(IR_GATE_PIN), 0, 1023, 0, 100) > IR_GATE_TRIP) ||		//switch or IR gate.
                     dartCountingSwitch.wasPressed()) )
                  ? 1 : 0);
}

void checkForDartsFired () {
  if (isCheckingForDartsFired && 																					//if checking for darts being fired. Not all
      (fireMode == SINGLE_FIRE || fireMode == BURST_FIRE)) {									// modesneed to check if a dart is fired
    byte dartsToFire = (fireMode == SINGLE_FIRE ? 1 : 3);									//determine max amounts of darts to be fired
    if (dartsFired < dartsToFire) {																				//if can still fire (hasn't reached threshold of
      digitalWrite(MOTOR_OUTPUT_PIN, HIGH);																//how many darts can fire), power pusher motor
    } else if (dartCountingSwitch.isPressed() && 													//if can't fire anymore darts and pusher
               dartsFired >= dartsToFire) {																					//retracted
      resetDartsFired();																									//Reset darts fired stuff so it can happen again
    }
  }
}

//do all the fancy select fire stuff
void selectFire () {
  trigger.read();																												//read trigger
  if (trigger.isPressed()) {      																			//check of trigger is pressed
    if (fireMode == SAFETY) {       																	//if in safety mode, turn off motor
      digitalWrite(MOTOR_OUTPUT_PIN, LOW);
    } else if (fireMode == SINGLE_FIRE || fireMode == BURST_FIRE) {		//if in burst fire or single shot mode
      isCheckingForDartsFired = true;																//allow for darts to be fired, handled elsewhere
    } else if (fireMode == FULL_AUTO) {     													//if full auto turn on motor
      digitalWrite(MOTOR_OUTPUT_PIN, HIGH);
    }
  } else if (!trigger.isPressed()) {    																//if trigger isn't pressed
    if (fireMode == FULL_AUTO || fireMode == SAFETY) {								//if firemode is fullauto or safety, turn off motor
      digitalWrite(MOTOR_OUTPUT_PIN, LOW);
    } else if ( !isCheckingForDartsFired 															//if all darts fired
                && (fireMode == SINGLE_FIRE || fireMode == BURST_FIRE) ) {     	//and in burstfire
      resetDartsFired();																							//reset darts fired stuff
    }
  }
}

void resetDartsFired () {
  digitalWrite(MOTOR_OUTPUT_PIN, LOW);																		//turn of motor
  dartsFired = 0;																													//darts fired set to 0
  isCheckingForDartsFired = false;																				//no longer checking if darts are being fired
}

thank you for the huge help! the happiness i have now is beyond me wow, it’s just something to see our code working and done compiling.

(deleted)

I don't want to rain on your parade but just because the code compiles it does not mean that it does what you want

Take this line, and others like it, for instance

fireMode == SAFETY;

I assume that you are trying to set fireMode to SAFETY. However, what you are actually doing is to compare the two values and then disregarding the result. The compiler actually alerts you to this if you have compilation messages turned on. The syntax is not wrong, just used wrongly so no actual error is reported

= is for assignment
== is for comparison

To test your code and hardware you will almost certainly need to insert Serial.print()s in strategic ares of the code so that you can verify the program flow and print pertinent variables at place such as before testing the value of the variables. When doing so it is a good idea to print test labels so that you know what you are printing and where

This can be tedious, but with any program beyond trivial it is often necessary

alright i’ll try your method and edit the part where i should have written = instead of ==. Thank you!

Post your code again when you have made the changes and I will have another look for anything obviously wrong

here you go, please also have a look through the code and see if it would do what i am hoping for, use a rotary switch to select firing modes, and for the blaster to only fire the appropriate amount of darts

/*----------------------------------------------------------------------*
   nerf-select-fire RapidStrike v1.0
   Andrew William, March 2020
 *                                                                      *
   Arduino sketch for saftey, single shot, three round burst, and full
   auto.
  ----------------------------------------------------------------------*/

#include <JC_Button.h>																											//library to deal with buttons easier

//pins
#define IR_GATE_PIN 0																											//analog input
#define TRIGGER_PIN 11              																			//digital input
#define DART_COUNTER_SWITCH_PIN 4   																			//digital input
#define MOTOR_OUTPUT_PIN 3          																			//digital output
#define ROT_SW_SAFETY_PIN 6                                               //digital output
#define ROT_SW_SEMI_AUTO_PIN 7                                            //digital output
#define ROT_SW_BURST_FIRE_PIN 8                                           //digital output
#define ROT_SW_FULL_AUTO_PIN 9                                            //digital output

#define NUM_OF_ROT_SW_PINS 4
// Array of all rotary switch pins so it's easier to iterate through all of them
const uint8_t ROT_SW_PINS[] = {ROT_SW_SAFETY_PIN, ROT_SW_SEMI_AUTO_PIN, ROT_SW_BURST_FIRE_PIN, ROT_SW_FULL_AUTO_PIN};

//for buttons/switches
#define PULLUP true        																								//internal pullup, so we dont need to wire resistor
#define INVERT true      																									//invert required for proper readings with pullup
#define DEBOUNCE_MS 20 																										//check btn time every 20ms

#define IR_GATE_TRIP 90																										//'trip' value for IR gate					

//code for fire modes. 4 modes total
#define SAFETY 0																													//SAFTEY is mode 0
#define SINGLE_FIRE 1																											//singe fire is mode 1
#define BURST_FIRE 2																											//burst fire is mode 2
#define FULL_AUTO 3																												//full auto is mode 3


byte fireMode = 0;   																											//keep track of fire modes.
byte dartsFired = 0;																											//keep track of how many darts fire
bool isCheckingForDartsFired = false;																			//some modes need to check if a certain number of darts to fire

Button trigger (TRIGGER_PIN, PULLUP, INVERT, DEBOUNCE_MS);														//trigger button, using the library
Button dartCountingSwitch (DART_COUNTER_SWITCH_PIN, PULLUP, INVERT, DEBOUNCE_MS);			//dart counting button, using the library

void setup () {
  pinMode(MOTOR_OUTPUT_PIN, OUTPUT);																		//set motor output pin to an output pin
  digitalWrite(MOTOR_OUTPUT_PIN, LOW);        													//make sure motor is off
  //reset all dart firing values so they dont get messed up later
}

void loop () {
  whatSW();																										//constantly check for changes in firemodes
  fire();																																//constantly check if dart is fired
  checkForDartsFired();																									//do stuff if dart is fired
  selectFire();																													//do fancy select-fire stuff
  resetDartsFired();

  static int LASTSW; {
    int SWREAD = whatSW();

    if (SWREAD != LASTSW) {
      // DOSOMETHING
      if (SWREAD == 1) {
        fireMode = SAFETY;
      }
      if (SWREAD == 2) {
        fireMode = SINGLE_FIRE;
      }
      if (SWREAD == 3) {
        fireMode = BURST_FIRE;
      }
      if (SWREAD == 4) {
        fireMode = FULL_AUTO;
      }
      LASTSW =  SWREAD;
      resetDartsFired();

    }

  }

}


int whatSW() {
  if (digitalRead(6)) {
    return 1;
  }
  if (digitalRead(7)) {
    return 2;
  }
  if (digitalRead(8)) {
    return 3;
  }
  if (digitalRead(9)) {
    return 4;
  }
  return 0;

}


//when dart fired
void fire() {
  dartCountingSwitch.read();																							//read button
  dartsFired += ( (isCheckingForDartsFired && 														//detect and keep track if dart is fired through
                   ( (map(analogRead(IR_GATE_PIN), 0, 1023, 0, 100) > IR_GATE_TRIP) ||		//switch or IR gate.
                     dartCountingSwitch.wasPressed()) )
                  ? 1 : 0);
}

void checkForDartsFired () {
  if (isCheckingForDartsFired && 																					//if checking for darts being fired. Not all
      (fireMode == SINGLE_FIRE || fireMode == BURST_FIRE)) {									// modesneed to check if a dart is fired
    byte dartsToFire = (fireMode == SINGLE_FIRE ? 1 : 3);									//determine max amounts of darts to be fired
    if (dartsFired < dartsToFire) {																				//if can still fire (hasn't reached threshold of
      digitalWrite(MOTOR_OUTPUT_PIN, HIGH);																//how many darts can fire), power pusher motor
    } else if (dartCountingSwitch.isPressed() && 													//if can't fire anymore darts and pusher
               dartsFired >= dartsToFire) {																					//retracted
      resetDartsFired();																									//Reset darts fired stuff so it can happen again
    }
  }
}

//do all the fancy select fire stuff
void selectFire () {
  trigger.read();																												//read trigger
  if (trigger.isPressed()) {      																			//check of trigger is pressed
    if (fireMode == SAFETY) {       																	//if in safety mode, turn off motor
      digitalWrite(MOTOR_OUTPUT_PIN, LOW);
    } else if (fireMode == SINGLE_FIRE || fireMode == BURST_FIRE) {		//if in burst fire or single shot mode
      isCheckingForDartsFired = true;																//allow for darts to be fired, handled elsewhere
    } else if (fireMode == FULL_AUTO) {     													//if full auto turn on motor
      digitalWrite(MOTOR_OUTPUT_PIN, HIGH);
    }
  } else if (!trigger.isPressed()) {    																//if trigger isn't pressed
    if (fireMode == FULL_AUTO || fireMode == SAFETY) {								//if firemode is fullauto or safety, turn off motor
      digitalWrite(MOTOR_OUTPUT_PIN, LOW);
    } else if ( !isCheckingForDartsFired 															//if all darts fired
                && (fireMode == SINGLE_FIRE || fireMode == BURST_FIRE) ) {     	//and in burstfire
      resetDartsFired();																							//reset darts fired stuff
    }
  }
}

void resetDartsFired () {
  digitalWrite(MOTOR_OUTPUT_PIN, LOW);																		//turn of motor
  dartsFired = 0;																													//darts fired set to 0
  isCheckingForDartsFired = false;																				//no longer checking if darts are being fired
}

I have had a look and there are no obvious problems with the code but following the logic is another matter, which is often the case with someone else's code. At least now it compiles !

One minor point. You have gone to great pains to give variables and constants meaningful names then in the whatSW() function you use pin numbers, which is a shame from the point of view of making the code readable. The function also returns anonymous numbers where it would be better to return a named value

I also note that you call the function in loop() and ignore the returned value. When you call it again soon after then my point about using names for the returned value comes into play. If you were to return a named value then you could assign it directly to fireMode and avoid the if/else tests

While using the whatSW named value would make a simpler code, i dont think i am going to go to the hassle of editing the whole code and remove the fireMode if/else arguments.

But thank you for the head up though!

right so i began testing, VCC to trigger switch to Pin 11, VCC to dart counter switch to Pin 4, VCC jumpered to Pin 9 (to simulate being in full auto mode), VCC + Ground and signal wire (from Pin 3) to relay.

currently, the relay is being in a closed state all the time, which means it is receiving power from Pin 3. Which means, neither the select fire, trigger, or dart counter is recognized by the arduino. Can anybody help me with this issue?

also, how do i make a serial monitor output so i know what is happening inside the arduino? what input is the arduino receiveing, what output is it receiving etc?

, how do i make a serial monitor output so i know what is happening inside the arduino

By adding labelled prints of variable values to your code.

additionally, I noticed PIN 3 (MOTOR_OUTPUT_PIN) to be as an input, while i have coded it to be an Output in void setup

Any clue off whats going on?

You’re the guy with the hardware…

I don't understand how it is a hassle to change

 static int LASTSW; {   // what's this { here for?
    int SWREAD = whatSW();

    if (SWREAD != LASTSW) {
      // DOSOMETHING
      if (SWREAD == 1) {
        fireMode = SAFETY;
      }
      if (SWREAD == 2) {
        fireMode = SINGLE_FIRE;
      }
      if (SWREAD == 3) {
        fireMode = BURST_FIRE;
      }
      if (SWREAD == 4) {
        fireMode = FULL_AUTO;
      }

to

 static int LASTSW; 
    int SWREAD = whatSW();

    if (SWREAD != LASTSW) {
      // DOSOMETHING
      fireMode = SWREAD - 1;  // Maybe even change whatSW to return 0 - 3 so you don't need the - 1 here.
      }

currently, the relay is being in a closed state all the time

Have you allowed for the fact that it is probably active LOW, ie the relay closes when its control input is taken to GND ?