Jump to content

Dispatching cockpit sounds in device


Recommended Posts

I wrote a how-to about this over a year ago for the A-4 devs, but I guess I should share it here.

 

https://pastebin.com/uKzbkhnA

 

Still no idea about how to do custom external sounds. Supposedly a sound API was released by ED devs, but nobody I know has ever figured out how to use it.

 

Thank you. My other question is queuing my engine crank with the icommand engine start commands. I have my electrical system fully coded but how do I prevent starting if my jet isnt prepared for starting?

 

Would just doing a simple if statement work?

 

"if (jet isnt ready) then if pilot icommandStart then (dispatch(icommandStop))"?

Link to comment
Share on other sites

Thank you. My other question is queuing my engine crank with the icommand engine start commands. I have my electrical system fully coded but how do I prevent starting if my jet isnt prepared for starting?

 

Would just doing a simple if statement work?

 

"if (jet isnt ready) then if pilot icommandStart then (dispatch(icommandStop))"?

 

You could undo the command like you are proposing, but I prefer to have wrapper-like functionality around built-in commands (SFM in this case). To do this, you would create a new custom key command that would dispatch the native engine start command only when your internal logic determines it is ready to do so. The original key command ID would be changed to the new custom one, so it is not possible to directly start the engone without going through your logic. Obviously, someone could go back into the default.lua and add it back in.

Link to comment
Share on other sites

If I use play_once() in the If statement I want it to play it doesn't work. But if I use it in the else part of the If statement I want it works and plays when I want? play_continue() works where I want in the if statement...

 

So confused :(


Edited by Wabacku
Link to comment
Share on other sites

If I use play_once() in the If statement I want it to play it doesn't work. But if I use it in the else part of the If statement I want it works and plays when I want? play_continue() works where I want in the if statement...

 

So confused :(

 

I would have to see your logic to know exactly what you mean, but what might be happening is that the sound is being told to play once every iteration, which restarts the sound audio at the beginning over and over, so you will never actually hear it play through the whole sound. That is the purpose of checking the is_playing function to avoid telling a sound to play when it is already playing.

 

The play_continue function, on the other hand, will internally loop through the entire sound audio before restarting, so you will hear it, even if you run that function every iteration.

 

Don't forget to tell the sound to stop when it should, even when it is only being told to play once. The sound will not automatically update its internal state after it is finished playing the audio. That is why the data structures I wrote for handling sounds included the sound length that I measured in a sound editing program.

Link to comment
Share on other sites

I would have to see your logic to know exactly what you mean, but what might be happening is that the sound is being told to play once every iteration, which restarts the sound audio at the beginning over and over, so you will never actually hear it play through the whole sound. That is the purpose of checking the is_playing function to avoid telling a sound to play when it is already playing.

 

The play_continue function, on the other hand, will internally loop through the entire sound audio before restarting, so you will hear it, even if you run that function every iteration.

 

Don't forget to tell the sound to stop when it should, even when it is only being told to play once. The sound will not automatically update its internal state after it is finished playing the audio. That is why the data structures I wrote for handling sounds included the sound length that I measured in a sound editing program.

 

Ahh, okay. I guess your playSoundOnce function doesnt work anymore... I re wrote it and it sort of worked, but I couldn't get it to update the state to stopped. So, the sound would only play once when I flipped the switch the first time and never again. Anyway, your play once function gives the same results as play_once().

 

So it is just updating the sound to play again at the update rate. I just dont know how to edit your function to make it work. I made it play once by initiating and running a counter - as it == a certain time it played. I guess it wasnt a real counter since it updated only at the function call, but it looked like:

 

i = 0

 

func()

i = i +1

if i == 1 then play

 

 

Dont think you can reset the counter though... So it only plays each sound once and that sound can never play again...

 

EDIT: Im trying to play sounds from the update part.

 

EDIT #2: Got it working - still would be nice to play through the update()


Edited by Wabacku
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...