[Solved] How to use command aSound.Play with aSound as a variable name?

Started by BrightBulb, Sat 25/04/2020 16:25:23

Previous topic - Next topic

BrightBulb

I'm aware how it's possible to play sounds with the command aSound.Play with aSound being the name of the audio file to be played.

Is there a way to have the command play a certain audio file by just supplying a variable?

Example:
For a RPG I made a struct for all the items in the game that handles all the items' properties like names, graphic, cost etc. I'd like to make a new entry for the struct to store a specific audio file for each item that I can later play by referring to the structs audio variable.


Crimson Wizard

You could store a variable of type AudioClip* in the struct and assign the clip you want there.
If that's not possible for some reason, perhaps store clip ID instead (integer), which is an index in Game.AudioClip[] array.
If you definitely want to have this as a string (script clip name or filename), then only way is to write a function with a large switch which would return an AudioClip* chosen based on this name.

BrightBulb

Thanks for the tip.

I used AudioClip* to manage the sound files and it works in general.

But I've recognised something odd. I've loaded some WAV-files into the editor und I can play all of them in the editor. But if I use them in the script some of them won't play. If I replace them with other files it works, so it is no scripting issue. The problem seems to lie in the files itself.

Is there anything peticular I have to look out for when using WAV files?

Cassiebsg

I suggest you use ogg.

think that if the WAV file is too short, then it won't play (it ends before it can start, you can add silence before/after to make the file longer if you really want WAV).
I always use ogg, but seen people often complain about problems with wav files (and I think that's the problem, but can't remember if it's anything else).
There are those who believe that life here began out there...

Crimson Wizard

Quote from: BrightBulb on Sun 26/04/2020 23:20:01
But I've recognised something odd. I've loaded some WAV-files into the editor und I can play all of them in the editor. But if I use them in the script some of them won't play. If I replace them with other files it works, so it is no scripting issue. The problem seems to lie in the files itself.

Is there anything peticular I have to look out for when using WAV files?

I only know that such problem exists, but don't know much detail. WAV is a fairly diverse group of formats, and the audio lib engine uses currently is old, and does not recognize all of them. The situation may change after we upgrade the audio lib.

BrightBulb

Thanks for your insight on this matter.

I converted the WAV files to OGG and now it works fine. The sound files are indeed very short, so this seemed to be the problem.

Thank you for your help.

SMF spam blocked by CleanTalk