oboyoberta Posted March 16, 2015 Report Share Posted March 16, 2015 I was intrigued by one of your post pete about using LUA for playing sound. I have a hardware piece made of 15 mom switches. Each switch when presse will play a announcement when pressed. Each switch has its own LUA and the Buttons are selected in FSUIP. They all work fine - sort of. (im not a programmer) but have created a script to run a sound file in a loop and will run in conjuction with a timer, and works fine. However, If I wanted to play a different announcment, I cannot stop the current sound from playing. I choose a seperate button and selected LUAKILLALL, but it does nothing- except kill the timer, but not the sound file. I'm quite confused about the luakillall, luakill (running lua script). Like I said, all the sounds will play (once) but if I select a different button, while one sound is playing, it will play the sound over the top of the running sound. Pete, I have looked over the LUA documentation and tried many variations, but not being a programmer, I'm sure I'm missing something. Any help would be most appreciated. (I know how often you chastise people for not putting enough effort in and I have spent will over a week on this one problem without success) Thank you, and we all are so appreciative of your availability in helping us with our cockpit builds. Don Each buttons Lua is just simple : ref sound.play("safety") This is the script I use for the timer and loop. ref = sound.playloop("safety")lastTimeProcessed = os.clock()function IsTimeToProcess(currentTime) span = currentTime - lastTimeProcessed if span >=30 then lastTimeProcessed = currentTime return true end return falseendwhile true do if IsTimeToProcess(os.clock()) then sound.stop(ref) end end Link to comment Share on other sites More sharing options...
Pete Dowson Posted March 16, 2015 Report Share Posted March 16, 2015 (im not a programmer) but have created a script to run a sound file in a loop and will run in conjuction with a timer, and works fine. However, If I wanted to play a different announcment, I cannot stop the current sound from playing. I choose a seperate button and selected LUAKILLALL, but it does nothing- except kill the timer, but not the sound file. I'm quite confused about the luakillall, luakill (running lua script). Lua Kill merely ruthlessly terminates the thread running that Lua program. It can't stop some activity, carried out in this case by the sound driver, continuing doing whatever your Lua program instigated. "sound.stop" is the only function which will stop a sound set to loop. lastTimeProcessed = os.clock() Interesting you went to the trouble of finding that function. You could have used the built in one, ipc.elapsedtime. If you want to stop the sound prematurely I suggest you use an event.Probably the best is to use event.param, and assign whatever button you wish to use to "LuaValue" to set the parameter. The event.param should call a function to stop the sound. In fact, if you have many sounds but you want to only play one at a time, you might find it neater to play them all in one Lua program, using the parameter value from an event to determine which one to play, automatically terminating the previous one. Note that event based programs do not terminate themselves, and you'd normally start the program using the [Auto] facility in the INI file to run it at program start up. It could just sit there waiting for the right parameter call to start a sound. Pete Link to comment Share on other sites More sharing options...
oboyoberta Posted March 16, 2015 Author Report Share Posted March 16, 2015 Thank you Pete, that was a big help. Don Link to comment Share on other sites More sharing options...
Pete Dowson Posted March 17, 2015 Report Share Posted March 17, 2015 Thank you Pete, that was a big help. Don I forgot also to suggest the use of event.timer to give your 30 seconds playing time. Use event.timer with 30 secs set when you start a sound, then event.delete for that timer call when you do stop it. Then the whole thing is ultra efficient ;-), being completely event based and therefore not actually occupying the processor much at all. I realised, afterwards, that if you don't do this change as well as what I suggested then what I suggested won't work, because events cannot be triggered UNTIL your program exits -- they operate on a program waiting for such, not on one looping continuously. Pete Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now