"A function-definition is not allowed here before '{' token"

I’m trying to make a joystick from an arduino uno r3. I so far have this code

/* Delayed Fight Stick
  Alan Chatham - 2012
  
  This code uses the UnoJoy library to implement a fight stick
   that has a 1 second delay between when it recieves the input
   and when it delivers that data to the console.
   
  It utilizes a ring buffer, where the input from the buttons
   is stored just behind where the output is drawn from, so
   the output will always be the least-fresh data available.
   In this way, every command the controller reads is preserved
   and sent out, just with a lag depending on the controller's
   rate of button polling and the size of the buffer.  
*/
#include "UnoJoy.h"

// This is the lag amount, in milliseconds
const int InputDuration = 0;

// These are the pin definitions for the 
//  input buttons and sticks.
byte SquarePin = 4;
byte TrianglePin = 5;
byte CirclePin = 6;
byte CrossPin = 7;
byte StartPin = 8;
byte LEDPin = 2;
byte SpeakerPin = 3;
byte SyncPin = 9;
byte NavModePin = 10;

byte LeftStickXPin = A0;
byte LeftStickYPin = A1;
byte RightStickXPin = A2;
byte RightStickYPin = A3;

const int ControllerUpdateRate = 20;
const int RingBufferSize = InputDuration / ControllerUpdateRate;
dataForController_t ControllerDataRingBuffer[RingBufferSize];
int InputDataIndex = 0;
int OutputDataIndex = 0;

void setup(){
// Set up button pins as input, internal pull-up on
pinMode(SquarePin, INPUT);
digitalWrite(SquarePin, HIGH);
pinMode(TrianglePin, INPUT);
digitalWrite(TrianglePin, HIGH);
pinMode(CirclePin, INPUT);
digitalWrite(CirclePin, HIGH);
pinMode(CrossPin, INPUT);
digitalWrite(CrossPin, HIGH);
pinMode(StartPin, INPUT);
digitalWrite(StartPin, HIGH);
pinMode(NavModePin, INPUT);
digitalWrite(NavModePin, HIGH);
// Set up our LED pin as an output
pinMode(LEDPin, OUTPUT);
digitalWrite(LEDPin, LOW);
// Set up our sync pin
pinMode(SyncPin, INPUT);
digitalWrite(SyncPin, HIGH);
// Set up our ring buffer with zeroed controller data packets
for (int i = 0; i < RingBufferSize; i++){
  ControllerDataRingBuffer[i] = getBlankDataForController();
}

void loop(){
if (digitalRead(NavModePin) == LOW){
   setControllerData(readController());
}
else{
  turnLoop();
}
}

dataForController_t readController(){
dataForController_t controllerData = getBlankDataForController();
if (digitalRead(SquarePin) == LOW)
  controllerData.squareOn = 1;
if (digitalRead(TrianglePin) == LOW)
  controllerData.triangleOn = 1;
if (digitalRead(CirclePin) == LOW)
  controllerData.circleOn = 1;
if (digitalRead(CrossPin) == LOW)
  controllerData.crossOn = 1;
if (digitalRead(StartPin) == LOW)
  controllerData.startOn = 1;
  
controllerData.leftStickX = analogRead(LeftStickXPin) >> 2;
controllerData.leftStickY = analogRead(LeftStickYPin) >> 2;
controllerData.rightStickX = analogRead(RightStickXPin) >> 2;
controllerData.rightStickY = analogRead(RightStickYPin) >> 2;
return controllerData;
}

(I hope that posted correctly)

These are the errors I’m getting

Arduino: 1.8.7 (Windows 10), Board: "Arduino/Genuino Uno"

D:\Documents\Arduino\Turn_Based_Fight_Stick_Master_Edited\Turn_Based_Fight_Stick_Master_Edited.ino: In function 'void setup()':

Turn_Based_Fight_Stick_Master_Edited:68:12: error: a function-definition is not allowed here before '{' token

void loop(){
          ^
Turn_Based_Fight_Stick_Master_Edited:95:1: error: expected '}' at end of input
}
^
exit status 1
a function-definition is not allowed here before '{' token

I’ve checked all the brackets and they looked good. If someone can please point me in the right direction here.

(I hope that posted correctly)

You posted this in the wrong section :wink: This is not related to avrdude, stk500 or bootloader. You can ask a moderator to move it to the programming section by clicking the 'report' link under your post.

Learn to indent your code properly in the IDE; use menu tools -> auto format.

After an auto-format, all functions should start at the beginning of a line. If not, you have a mismatch between { and }.

After auto-format, yours looks like

...
...
void setup() {
  ...
  ...
  void loop() {
    ...
    ...

This indicates that you're missing a closing } for the setup() function.

thanks