Because the first argument required by audio_play_sound() isn't a string, it's an index.Why does the above code not work?Code:snd_string = 'snd_szymat_echo_party' audio_play_sound(snd_string,10,true);
Do I have to convert the string to something else first?
snd_string = asset_get_index(snd_szymat_echo_party);
audio_play_sound(snd_string,10,true);
asset_get_index() takes a string. It should beBut strange enough it is still not working for me, I have the following code now:
Code:snd_string = asset_get_index(snd_szymat_echo_party); audio_play_sound(snd_string,10,true);
snd_string = asset_get_index("snd_szymat_echo_party");
I knew there are strings, numbers, and all that kind of arguments, but was not aware yet that each function requires specify type or arguments until now. Thats really good to be aware of thanks!The manual included with GMS2 explains what type each argument of built-in functions should be. Make it your first stop when you're having issues; you'll be surprised at how often it will be your last stop!
When you are in the code editor, if you middle click the function name it will open the manual on the page for that function where you can check the required arguments, read about the function and also check the code example at the bottom of the page to see how it is used.ah yes, it finaly works now!
I knew there are strings, numbers, and all that kind of arguments, but was not aware yet that each function requires specify type or arguments until now. Thats really good to be aware of thanks!
Amazing, that middle mouse click on functions is really good!When you are in the code editor, if you middle click the function name it will open the manual on the page for that function where you can check the required arguments, read about the function and also check the code example at the bottom of the page to see how it is used.
snd_to_play = snd_szymat_echo_party;
audio_play_sound(snd_to_play, 10, true);
snd_string = "snd_szymat_echo_party";
audio_play_sound(asset_get_index(snd_string), 10, true);
audio_play_sound(snd_szymat_echo_party, 10, true);
It may be pointless in this particular case, but there are other cases where storing resource IDs in variables and then referencing them later is a valid technique. That's why it's important to master the distinction and learn how to do this properly.But in this case it looks like something pointless as you can just use:
snd_szymat_echo_party is already the indexCode:audio_play_sound(snd_szymat_echo_party, 10, true);
enum ANNOUNCER {
ALICE,
BOB,
CAITLYN
}
ini_open(working_directory + "settings.ini");
global.announcer = int64(ini_read_real("sfx", "announcer", 0));
ini_close();
global.snd_letsgo = [snd_alice_letsgo, snd_bob_letsgo, snd_caitlyn_letsgo];
audio_play_sound(global.snd_letsgo[global.announcer], 10, false);
Yes I meant in this particular case it seamed a little pointlessIt may be pointless in this particular case, but there are other cases where storing resource IDs in variables and then referencing them later is a valid technique. That's why it's important to master the distinction and learn how to do this properly.
Here is an example:
Code:enum ANNOUNCER { ALICE, BOB, CAITLYN } ini_open(working_directory + "settings.ini"); global.announcer = int64(ini_read_real("sfx", "announcer", 0)); ini_close(); global.snd_letsgo = [snd_alice_letsgo, snd_bob_letsgo, snd_caitlyn_letsgo];
Code:audio_play_sound(global.snd_letsgo[global.announcer], 10, false);
the reason is because I have a room with a jukebox where players can choose to play a disk of choice out of 100+ unique tracks.But in this case it looks like something pointless as you can just use:
snd_szymat_echo_party is already the indexCode:audio_play_sound(snd_szymat_echo_party, 10, true);