Soundman Posted December 14, 2010 Report Posted December 14, 2010 Hello Pete, First off thanks for a great program. Secondly, you've enspired me to actually code my own little projects with FSUIPC. (I am a audio mixer/recordist/musican with no programming experience whatsoever). I've created a little lua file to play .wavs of a captain's initial announcement. Starting with "Good Morning" or "Good Afternoon" or "Evening depending on the time of the local hour, and then give information about the departure. Clear, Rain, Snow, windy...etc. please see my example: ====================================================== Lua File --Captain Announcement time = ipc.readUB(0x0238) -- TIME OF DAY LOCAL HOUR (0-23) weather = ipc.readUB(0x04CC) -- WEATHER 0=No rain 1=Rain 2= Snow if time <= 10 then sound.play("f:\\fsv_crew\\captain\\morning.wav") end if (time >= 11) and (time <= 15) then sound.play("f:\\fsv_crew\\captain\\afternoon.wav") end if time >= 16 then sound.play("f:\\fsv_crew\\captain\\evening.wav") end ipc.sleep(3000) == Each file is 3 seconds long if (weather == 0) then sound.play("f:\\fsv_crew\\captain\\clearsky.wav") end if (weather == 1) then sound.play("f:\\fsv_crew\\captain\\rain.wav") end if (weather == 2) then sound.play("f:\\fsv_crew\\captain\\snow.wav") end ================================================== And it works great! Except for using the ipc.sleep command to link the two files. I've tried using the sound.query( ) command every which way with no results I thought I could code it like this: ================================================= if (sound.query("f:\\fsv_crew\\captain\\morning.wav")) and (sound.query("f:\\fsv_crew\\captain\\afternoon.wav")) and (sound.query("f:\\fsv_crew\\captain\\evening.wav")) == false then if (weather == 0) then sound.play("f:\\fsv_crew\\captain\\clearsky.wav") end if (weather == 1) then sound.play("f:\\fsv_crew\\captain\\rain.wav") end if (weather == 2) then sound.play("f:\\fsv_crew\\captain\\snow.wav") end end ================================================== But, it just plays the first file (time) . Am I thinking of the sound.query() command correctly? I hope you can enlighten me as to what I am doing wrong. If it's not possible, I am still content with using the sleep command. I just have to be diligent about the length of the files. Thanks in advance. Jim 1
Pete Dowson Posted December 14, 2010 Report Posted December 14, 2010 And it works great! Except for using the ipc.sleep command to link the two files. Is this your line: ipc.sleep(3000) == Each file is 3 seconds long?If so it is wrong. Comments are started by -- not ==. If you only just added the == comment for posting here, then can you explain what goes wrong when you use sleep? if (sound.query("f:\\fsv_crew\\captain\\morning.wav" )) and (sound.query("f:\\fsv_crew\\captain\\afternoon. wav")) and (sound.query("f:\\fsv_crew\\captain\\evening.wav" )) == false then That's all wrong. The sound is identified by a reference, the one called 'ref' in the documentation, returned specifically for later references in the query and stop commands. Did you not notice the "ref = ..." parts in the play commands, to give you the reference to use? It does actually say: The "ref" value returned is a number which can be used subsequently in the stop, adjust and query functions. Regards Pete
Soundman Posted December 14, 2010 Author Report Posted December 14, 2010 If you only just added the == comment for posting here, then can you explain what goes wrong when you use sleep? Yes, I did add that to the post by mistake. And, the sleep command works very well when precisely timed to the .wav file playing. The sound is identified by a reference, the one called 'ref' in the documentation, returned specifically for later references in the query and stop commands. Did you not notice the "ref = ..." parts in the play commands, to give you the reference to use? It does actually say: Bing! the light just went on thanks. I'll work on that. And a real newbie question. Can "ref" be named anything I choose? Meaning... ref = sound.play(path to my wave) can be voice1 = sound.path(path to my wave) Thanks again.
Pete Dowson Posted December 15, 2010 Report Posted December 15, 2010 Can "ref" be named anything I choose? Yes, of course. ALL names of values ("variables" as they are known) used in the documentation are simply chosen to be suggestive of what they represent. The same applies to "offset" and "value" in the function parameters. There are some reserved names, like those for GoFlight devices (GFRP48 etc), and of course all of the library function names and Lua "reserved words", like "function", "then", "if" and so on. Just try to avoid clashes with anything that might be so mistaken. Please name variables to be meaningful to you, always. Same with your own function names. Pete
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