Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: selmiak on Sun 24/02/2019 20:53:23

Title: iterate through soundfiles
Post by: selmiak on Sun 24/02/2019 20:53:23
I have a lot of soundfiles called file1.mp3, file2.mp3, etc.
And I want to play them within in aloop, where I have a counter variable, let's call it i.

Code (ags) Select

i++;
aFile{i}.Play



i get incremented somewhere else and I want to play a new sound everytime this function with the audio play command is called. How would I browse through the filenames in script?
Title: Re: iterate through soundfiles
Post by: Snarky on Sun 24/02/2019 22:19:38
You can't.

The variable names in code are not in this sense "strings" that can be manipulated by the code (that would be self-modifying code, which is beyond AGS), they're just arbitrary labels to make the script readable to humans. To the compiler, there's no relationship between aFile01 and aFile02.

To iterate over clips, you need to have the AudioClips in an array. Here you have two options:

1. Manually add them to an array yourself.
2. Use Game.AudioClips[]

This second option is AGS's built-in array of all the AudioClips. The problem is that the ordering of the clips in that array is... unknown. It's somehow based on the order in which the clips were imported, or how they're ordered in the editor, but with subfolders it's not entirely clear. Is it possible to change the order? Who knows? You might have to experiment (or delve into engine/editor code, or ask Crimson Wizard or someone else to figure it out).
Title: Re: iterate through soundfiles
Post by: selmiak on Sun 24/02/2019 23:01:50
it would be too easy... so I decided to fill the array myself. And fail at doing this...

Quote
AudioClip* allaudioclips[60];
allaudioclips[1] = aFile1;
allaudioclips[2] = aFile2;

gives an error in the seconds line
Parse error: unexpected 'allaudioclips'
Title: Re: iterate through soundfiles
Post by: morganw on Sun 24/02/2019 23:43:13
That is valid, but you can only do the assignments inside a function.
Title: Re: iterate through soundfiles
Post by: selmiak on Mon 25/02/2019 01:15:16
yeah, right, thanks guys  ;-D