iterate through soundfiles

Started by selmiak, Sun 24/02/2019 20:53:23

Previous topic - Next topic

selmiak

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

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?

Snarky

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).

selmiak

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'

morganw

That is valid, but you can only do the assignments inside a function.

selmiak


SMF spam blocked by CleanTalk