Adding sound when using sword ?

Started by MetalZelda, October 13, 2015, 03:56:09 PM

Previous topic - Next topic
Hi
I was wondering if there is a way to add sound like random listed sound when using the sword ? I've tried to add sol.audio.sound_play in the sword item script with 'item:on_using()' but it doen't play the sound at all.
Oh and also is there a chance of someone to re-code in LUA the sword for making sword skills easily ?

For the sound, it's actually sol.audio.play_sound(sound_id). If you open the error.txt file, you will probably see that the function you called does not exist. Check the Lua API to know the functions you have:
http://www.solarus-games.org/doc/latest/index.html

To customize the use of the sword you can use some functions like:
game:on_command_pressed(command)
but it will take some work to script the desired behaviour. (I don't have time to make your script, but you can always ask for others help on the forum.)
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

Quote from: Diarandor on October 13, 2015, 04:13:41 PM
For the sound, it's actually sol.audio.play_sound(sound_id). If you open the error.txt file, you will probably see that the function you called does not exist. Check the Lua API to know the functions you have:
http://www.solarus-games.org/doc/latest/index.html

To customize the use of the sword you can use some functions like:
game:on_command_pressed(command)
but it will take some work to script the desired behaviour. (I don't have time to make your script, but you can always ask for others help on the forum.)

Fot the sol.audio i didn't see my mistake, it is indeed sol.audio.play_sound(sound_id) in item:on_using() as you called (I did a mistake while writing this thread :() but still don't work
For the sword thanks, I'll try asap

October 13, 2015, 04:33:08 PM #3 Last Edit: October 13, 2015, 04:36:57 PM by Diarandor
I think there is already a sound for the sword. Something like sword.ogg (or maybe with a different extension). You can try to replace that file with your sound, it could work. But that only works for the sword that is implemented in the engine. You can always fully script your own sword.

Edit: in your case, if you don't hear a sound, maybe the problem is that the event item:on_using() is not being called for some reason (maybe something is missing in your code).
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

October 13, 2015, 04:43:33 PM #4 Last Edit: October 13, 2015, 04:47:55 PM by Username
Quote from: Diarandor on October 13, 2015, 04:33:08 PM
I think there is already a sound for the sword. Something like sword.ogg (or maybe with a different extension). You can try to replace that file with your sound, it could work. But that only works for the sword that is implemented in the engine. You can always fully script your own sword.

Edit: in your case, if you don't hear a sound, maybe the problem is that the event item:on_using() is not being called for some reason (maybe something is missing in your code).

I'm using the default sword.lua in the "item" folder, that's maybe because the hardcoded sword can't interract with the sword.lua which is simply a call event. And thus can't call on_using() (I tried with MoS hookshot and bow which are too hardcoded and same thing occurs, nothing is played and no error are displayed (in the console and/or in the error.txt)
Your solution of the sword sounds sounds great, but I'm searching something to play 1 random sound each time you use that sword, I'll try to LUA the whole sword process (or do some hardcore modification directly from source code and re-compile), it might be more handy for what I'm searching  ;D

To choose a random sound, you can easily do it with the Lua random functions, like math.random(...), although maybe you already know that. Probably you need a random seed to make  the result a random number. This part should be a piece of cake. I put a link about the random function: http://www.lua.org/pil/18.html
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

Quote from: Diarandor on October 13, 2015, 07:15:17 PM
To choose a random sound, you can easily do it with the Lua random functions, like math.random(...), although maybe you already know that. Probably you need a random seed to make  the result a random number. This part should be a piece of cake. I put a link about the random function: http://www.lua.org/pil/18.html

This is quite useful indeed
Thanks ^^