Jump to content
The simFlight Network Forums

Lua sound question


Recommended Posts

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

  • Upvote 1
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.