English Rebel Posted June 28, 2013 Report Posted June 28, 2013 I just found this very nice little tutorial http://forum.simflight.com/topic/67235-how-to-install-a-lua-file-or-script/ that may suit what I'm trying to do (assign a sound file to a button push). When the Lua script has been written (I'll name it Stall Sound.lua), where should it be installed so it will appear in the FSUIPC Buttons + Switches page pull down list for Action taken when button is pressed?Thanks Alan
Pete Dowson Posted June 28, 2013 Report Posted June 28, 2013 When the Lua script has been written (I'll name it Stall Sound.lua), where should it be installed so it will appear in the FSUIPC Buttons + Switches page pull down list for Action taken when button is pressed? As documented, in the FS Modules folder alongside FSUIPC, its INI file and any Macro files you use. Full details of the Lua system in FSUIPC (and WideClient) are provided with lots of examples in the Lua package installed in your FSUIPC Documents folder, which is also in the FS Modules folder. Pete
English Rebel Posted June 29, 2013 Author Report Posted June 29, 2013 Okay thanks for that response. I'm trying to write a Lua script that will play a wav file whenever buttons on my test panel switch are pressed. The first one is the stall test and when the button is pressed the stall.wav file will play. I apologize in advance as this is the first time I've attempted a Lua script so please be patient with me. I used a Lua editor to compile the script and put it in the Modules folder as instructed. I have programmed the button and it's recognized in FSUIPC where I assigned the Lua script to it. I've played around with this for over an hour but the problem is that I don't understand the error message I'm getting in the script log file so maybe you can help here. This is the script (I used an existing wav file just to test the function) :razz: --Plays the stall warning WAV file when the stall test button is pressed-- function stall(stallwarning) Sound.playloop(stallwarning) end stall("E:Program Files (x86)\Microsoft Games\Microsoft Flight Simulator x\Sound\ORBX_Sound_dog_barking.wav") The log file gives me this error ***LUA ERROR*** E:Program Files (x86)\Microsoft Games\Microsoft Flight Simulator\Modules\Stall warning. lua:1: attempt to index global 'Sound (a nil value) Thanks Alan
Pete Dowson Posted June 29, 2013 Report Posted June 29, 2013 ***LUA ERROR*** E:Program Files (x86)\Microsoft Games\Microsoft Flight Simulator\Modules\Stall warning. lua:1: attempt to index global 'Sound (a nil value) It is telling you that there is nothing called "Sound" (it has a 'nil' value -- 'nil' means nothing!) The sound library is called "sound" NOT "Sound", as documented. Lua is sensitive to case. Please be more careful. Pete
English Rebel Posted June 30, 2013 Author Report Posted June 30, 2013 Oh, okay. Didn't think Lua was case sensitive in the file links -- just its own commands. Thanks Alan
Pete Dowson Posted June 30, 2013 Report Posted June 30, 2013 Oh, okay. Didn't think Lua was case sensitive in the file links -- just its own commands. Thanks Alan The "sound" which you got wrong is a library name, not a file link. Libraries are just lua objects, same as functions and variables. They are really just an array of functions. Pete
English Rebel Posted June 30, 2013 Author Report Posted June 30, 2013 Pete Okay I changed "sounds" to lower case and the error message has gone away -- thanks for that. However the sound does not play. The log file shows the Lua script starting and stopping okay (in fact six times -- I had the button depressed for about two seconds). I played the sound file and it's fine. Any suggestions? I have the Action to repeat while the button is held box checked. Thanks Alan
Pete Dowson Posted June 30, 2013 Report Posted June 30, 2013 Pete Okay I changed "sounds" to lower case and the error message has gone away -- thanks for that. However the sound does not play. The log file shows the Lua script starting and stopping okay (in fact six times -- I had the button depressed for about two seconds). I played the sound file and it's fine. Any suggestions? I have the Action to repeat while the button is held box checked. Thanks Alan Most likely it can't find the WAV file. Make sure any "\" characters in the path you provide are doubled, i.e. \\, because a single \ is an escape character which says the next character is a control. eg \n = new line. I thought you were using an example for this? If so you should surely have sen these things already? Pete
English Rebel Posted June 30, 2013 Author Report Posted June 30, 2013 Pete My example was the actual WAV file (barking dog :razz: ) not the script. The double \\ did it -- I said it was my first rookie attempt. :???: Works great. Thanks Alan
English Rebel Posted July 5, 2013 Author Report Posted July 5, 2013 Pete I have this Lua script to play a warning chime when a test switch is pushed. --Plays the master caution warning WAV file when the test button is pressed-- function warn(warningchime) Sound.play(warningchime) end warn("E:\\Program Files (x86)\\Microsoft Games\\Microsoft Flight Simulator x\\sound\warningchime.wav") This plays a single chime just fine but what do I need to add to play the sound three times? Also I created this Lua file by copying, renaming, and editing another Lua file that I had used successfully. It's in the modules folder but was not listed in the drop down list in Buttons + Switches. I exited and restarted FSX four times and even rebooted the PC but only after exiting and restarting FSX a further three times did it finally appear. Any thoughts? Thanks Alan
Pete Dowson Posted July 5, 2013 Report Posted July 5, 2013 This plays a single chime just fine but what do I need to add to play the sound three times? Either loop on the Sound.play three times or simply make three copies of that line. It would, however, be more efficient to make the WAV longer with the three copies included. Also I created this Lua file by copying, renaming, and editing another Lua file that I had used successfully. It's in the modules folder but was not listed in the drop down list in Buttons + Switches. I exited and restarted FSX four times and even rebooted the PC but only after exiting and restarting FSX a further three times did it finally appear. Any thoughts? I don't know what you are doing. You don't even have to exit FS let alone re-boot! Just press one of the "reload" buttons on the Buttons, Keys or Axes tabs. Pete
Pete Dowson Posted July 6, 2013 Report Posted July 6, 2013 BTW, I don't know why you are using a function, unless it is for programming practive. Your program: --Plays the master caution warning WAV file when the test button is pressed-- function warn(warningchime) Sound.play(warningchime) end warn("E:\\Program Files (x86)\\Microsoft Games\\Microsoft Flight Simulator x\\sound\warningchime.wav") is actually identical in effect to: Sound.play("E:\\Program Files (x86)\\Microsoft Games\\Microsoft Flight Simulator x\\sound\warningchime.wav") and to play it three times you could just do: Sound.play("E:\\Program Files (x86)\\Microsoft Games\\Microsoft Flight Simulator x\\sound\warningchime.wav") Sound.play("E:\\Program Files (x86)\\Microsoft Games\\Microsoft Flight Simulator x\\sound\warningchime.wav") Sound.play("E:\\Program Files (x86)\\Microsoft Games\\Microsoft Flight Simulator x\\sound\warningchime.wav") Pete
English Rebel Posted July 6, 2013 Author Report Posted July 6, 2013 Ah, thanks for that. I used function because I saw that in another Lua file, but I guess that was more complex. I'll change mine to the simpler version. As far as the Lua file not showing up, I didn't try the reload but shouldn't shutting down and restarting FSX make the file show up?Thanks Alan
Pete Dowson Posted July 6, 2013 Report Posted July 6, 2013 ... but shouldn't shutting down and restarting FSX make the file show up? Yes of course, if there;s room. The complete list of Lua files is read each time. The only reason a new one won't show is when the list is full. Only 127 can be accommodated for assignments. Pete
English Rebel Posted July 7, 2013 Author Report Posted July 7, 2013 Pete I edited the Lua file to list: Sound.play("E:\\Program Files (x86)\\Microsoft Games\\Microsoft Flight Simulator x\\sound\warningchime.wav") three times but it only plays once. Any ideas?Thanks Alan Edit I created another Lua file to play three different sounds and they all play at once. This is why the warning chime Lua only seems to play one chime when in fact it's playing all three at the same time. Is there a way to put a delay between the sound.play entries?Thanks Alan
Pete Dowson Posted July 7, 2013 Report Posted July 7, 2013 There's no queuing system in DirectSound. You can either loop teting whether the sound is still playing (i.e. using sound.query), or, if you know how long the sound plays for, just inserting an ipc.sleep(n) between them, where 'n' is the number of milliseconds. 91000 mSecs = 1 sec). Pete
English Rebel Posted July 7, 2013 Author Report Posted July 7, 2013 Okay I'll try ipc.sleep as I can measure the length of the sounds. This sounds (no pun intended :razz: ) as the easiest solution as I'm not very proficient at Lua. Thanks Alan
English Rebel Posted July 8, 2013 Author Report Posted July 8, 2013 There's no queuing system in DirectSound. You can either loop teting whether the sound is still playing (i.e. using sound.query), or, if you know how long the sound plays for, just inserting an ipc.sleep(n) between them, where 'n' is the number of milliseconds. 91000 mSecs = 1 sec). Pete Pete You got me going there for a while -- 91000 mSecs=1 sec. :razz: . I too have a habit of typing 9 when I meant ( -- particularly when in a hurry. Took a while for that number to sink into my thick skull as being way to large. :mrgreen: Alan
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