Author Topic: Adding sound when using sword ?  (Read 1819 times)

MetalZelda

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
Adding sound when using sword ?
« on: October 13, 2015, 03:56:09 pm »
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 ?

Diarandor

  • Hero Member
  • *****
  • Posts: 1044
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Adding sound when using sword ?
« Reply #1 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.)
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

MetalZelda

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
Re: Adding sound when using sword ?
« Reply #2 on: October 13, 2015, 04:27:17 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

Diarandor

  • Hero Member
  • *****
  • Posts: 1044
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Adding sound when using sword ?
« Reply #3 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).
« Last Edit: October 13, 2015, 04:36:57 pm by Diarandor »
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

MetalZelda

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
Re: Adding sound when using sword ?
« Reply #4 on: October 13, 2015, 04:43:33 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
« Last Edit: October 13, 2015, 04:47:55 pm by Username »

Diarandor

  • Hero Member
  • *****
  • Posts: 1044
  • Cats are cool! (ΦωΦ)
    • View Profile
Re: Adding sound when using sword ?
« Reply #5 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
“If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you.”

MetalZelda

  • Hero Member
  • *****
  • Posts: 551
    • View Profile
Re: Adding sound when using sword ?
« Reply #6 on: October 13, 2015, 08:15:53 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 ^^