a button input code that plays a different sound when each button is pressed

Hi,
I'm trying to make a button input puzzle that plays a different sound whenever you press a button. I'm trying to tweak code by Playful Technology (he used a DF mini player and I'm just using an SD reader module).

it'll usually only play a short buzz, but when I set it so that it plays the same audio clip regardless of which button is pressed it works fine so I don't think it's a problem with the wiring or audio files.

the files in the SD card are numbered 1-5.wav (as apposed to 0001 etc, but i've tried using 0001.wav to similar results).

any advice would be greatly appreciated

// DEFINES
// Provides debugging information over serial connection
#define DEBUG


// INCLUDES

#include <pcmConfig.h>
#include <pcmRF.h>
#include <TMRpcm.h>
#include <SPI.h>
#include <SD.h> 
#define SD_ChipSelectPin 10


// CONSTANTS
// Define the number of possible "inputs" - i.e. the number of switches, buttons etc. that the player can press
const byte numInputs = 4;
// What pins are those buttons connected to? (other wire should go to ground)
const byte inputPins[numInputs] = {2, 3, 4, 5};
// Define the number of steps in the sequence that the player must follow
const byte numSteps = 3;
// The correct sequence of inputs required to solve the puzzle.
const byte steps[numSteps] = {0, 3, 0}; // i.e. press button #2 once, then button #3 twice, then button #0, then button #1.
// This pin will be driven LOW to release a lock when puzzle is solved
const byte lockPin = A0;

// GLOBALS

TMRpcm tmrpcm;

// Assume the default state of each switch is HIGH. 
bool lastInputState[] = {HIGH, HIGH, HIGH, HIGH};
// What step of the sequence is the player currently on?
int currentStep = 0;

// Switches can "bounce" when they open/close, generating a flurry of false readings
// To prevent this, we'll add a short delay between each time an input value
// is read.
// The last time the input switch was toggled
unsigned long lastDebounceTime = 0;
// The amount of time (in ms) to wait before reading again 
unsigned long debounceDelay = 1000;

char fileName[5];
int fileToPlay ;


// Setup function runs once when first starting (or resetting) the board
void setup() {
  #ifdef DEBUG
    // Initialise serial communications channel with the PC
    Serial.begin(9600);
    delay(500);
  #endif
  

tmrpcm.speakerPin=9;
if(!SD.begin(SD_ChipSelectPin)){
  Serial.println("SD FAILED");
  return;
}
tmrpcm.setVolume(5);


  // Initialise the input pins that have switches attached
  for(int i=0; i< numInputs; i++){
    pinMode(inputPins[i], INPUT_PULLUP);
  }
  
  // Initialise the LED pins that show progress through the sequence 
//  for(int i=0; i< numSteps; i++){
//    pinMode(ledPins[i], OUTPUT);
//  }

  // Set the lock pin as output and secure the lock
  pinMode(lockPin, OUTPUT);
  digitalWrite(lockPin, HIGH);

 #ifdef DEBUG
    Serial.println(F("Lock secured"));
  #endif


fileToPlay=0;
sprintf(fileName, "%d.wav", fileToPlay);
 
  // Debug
  #ifdef DEBUG
    Serial.println("Setup Complete");
  #endif
}





// The main program loop runs continuously
void loop() {

  // Check that we've waited at least "debounceDelay" since last input
  if ( (millis() - lastDebounceTime) > debounceDelay) {
  
    // Loop through all the inputs
    for(int i=0; i<numInputs; i++){
      int currentInputState = digitalRead(inputPins[i]);

      // If the input has changed, reset the debounce timer
      if(currentInputState != lastInputState[i]) {
        lastDebounceTime = millis();    
      }
        
      // If the input is currently being pressed (and wasn't before)
      // Note that since the input pins are configured as INPUT_PULLUP,
      // they read as LOW when pressed and HIGH when not.
      if(currentInputState == LOW && lastInputState[i] == HIGH) {


 fileToPlay=inputPins[i++];
tmrpcm.play("fileToPlay");
      
        
      
        // Was this the correct input for this step of the sequence?
        if(steps[currentStep] == i) {
          currentStep++;
          
          #ifdef DEBUG
            Serial.print(F("Correct input! Onto step #"));
            Serial.println(currentStep);
          #endif
        }
        // Incorrect input!
        else {
          currentStep = 0;
          Serial.println(F("Incorrect input! Back to the beginning!"));
        }
      }
      
      // Update the stored value for this input
      lastInputState[i] = currentInputState;
    }
  }


  
  
  
  
  
  
  // Check whether the puzzle has been solved
  if(currentStep == numSteps){
    onSolve();
  }


}

// Takes action when the puzzle becomes solved
void onSolve(){

  #ifdef DEBUG
    // Print a message
    Serial.println(F("Puzzle Solved!"));
  #endif 

  // Release the lock
  digitalWrite(lockPin, LOW);

  // Loop forever
  while(true){


  }
}
       fileToPlay = inputPins[i++];
        tmrpcm.play("fileToPlay");

fileToPlay is a number but instead of playing the file corresponding to that number you send the string "fileToPlay" to the player. Why ?

Also, why do you increment i when you are inside a for loop that uses i as its counter ?

You do have some code that seems aimed at creating a filename based on the value of fileToPlay

  fileToPlay = 0;
  sprintf(fileName, "%d.wav", fileToPlay);

but it is only in the setup() function and is not used again.

Incidentally, the fileName array needs to be at least 6 characters in length in order for it to hold a 5 character filename plus the '\0' terminator

I'm still pretty new to using strings (outside of changing values of pre-existing code). I thought that by stating that fileToPlay was equal to another value, by telling the TMR to play that string it would be the same as telling it to play that value with ".wav" at the end because of the sprintf in setup.

in the original code that I'm evidently butchering, it used i to play the audio file that corresponds with that button input, but because the inputs started on 0 and the file names started at 0001, I assumed the i+1 in the original code was because of that.

Let's suppose that you want to play 0.wav when the first button becomes pressed, 1.wav when the second button becomes pressed and so on, then you need to work out which button has become pressed which will give you the first part of the filename. Then you can use sprintf() to insert a string corresponding to the button number into the filename at that time and use that filename with the tmrpcm.play() function