(name v.s 'a') is it possible?

Hello, im going to try and make this post be clearer than my last ones. This is a simple question. I have been doing research into variables and with help from people here im comfortable using them and such.
Now my question is with an example. My current function is setup as
playWAV('a', na_volume) the function is playWAV(char effect, na_volume) because it is in a case list. What i want to know is can i move from 'a' variables to 'alarm1' Is this even possible? I thought maybe strings but couldnt understand them.

void playWAV (char effect, int na_volume)
{
  Serial.println("Entered playWAV");
  switch (effect)
  {
    case 'a':
      file = new AudioFileSourceSD("/wav/alarm.wav");
      break;

    case 'b':
      file = new AudioFileSourceSD("/wav/alarmhigh.wav");
      break;

    case 'c':
      file = new AudioFileSourceSD("/wav/alarmlow.wav");
      break;

    case 'd':
      file = new AudioFileSourceSD("/wav/error.wav");
      break;

"alarm1" would be a string.
A switch/case only works on compile-time integer constants.

You could use a sprintf to form your file path name.

Can you provide an example of this? first time hearing about it. (and thank you, ive been getting a lot of people rude around here assuming im an idiot. So thank you for not being that way, its much appriciated.

void playWav (char* name)
{
  char buffer [40];
  sprintf (buffer, "wav/%s.wav", name);
  ...
  ...
}
  

playWav ("alarm");

Do those dynamically-created AudioFileSourceSD objects get deleted somewhere? If not, you're heading towards a memory leak.

so if ive got it right, char buffer [40]; would i change the 40 or not?
i get the "wav/%s.wav I would put the path there correct? and the name would be manually specified on that line too correcty?

thats probably true :slight_smile: i never saw anything about dumping them...

You'd only change the 40 if the pathname could exceed 39 characters.
The string pointed to by "name" will replace the %s, and you simply use "buffer" to open the file.

And I can do that in like a list format correct?

I don't know what that means.

now im assuming im an idiot :slight_smile:
Sorry, i meant like a list. ie

sprintf (buffer, "wav/%s.wav", name1);
sprintf (buffer, "wav/%s.wav", name2);
sprintf (buffer, "wav/%s.wav", name3);

That would just mean buffer contained the last one, i.e. whatever pathname "name3" represented

I don't know why you'd want to do that

so everytime i want to call a file id pretty much need to run a function with the file patch???

or would i change buffer for every file?

Again, I don't understand what "patch" is.

Tell me what you want to do, not how you think you should do it

it was a typo sorry meant path.....
so id need to run the whole function you wrote or would i just change buffer for every file

No, buffer contains the whole pathname you want to open.
You don't change it.

i want a list of files (like in the switch case) and instead of calling on them by a single letter, call on by a word

I thought that's what I'd given you.

Play around with sprintf and use Serial.print to print the string in "buffer"

I don't know where the 'a', 'b' etc come from

I had asked if you changed the name entry you said no I asked change buffer than, no

So how would I make more than 1 entry