Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I script this sound so it plays correctly?
genmills Offline
Junior Member

Posts: 47
Threads: 7
Joined: Mar 2011
Reputation: 0
#1
How can I script this sound so it plays correctly?

Hi guys,
if you have seen the other problems I have been talking about on the forum, then you know that I have been making a large, outdoor map which entails so much, and brings up a lot of things you might not have to script in other maps.

Here is today's problem:

I play ambient nighttime outside sounds (at the player so they always hear it) and I loop it. I put the function under OnEnter() because I always wanted to hear it when I went in and out of the different buildings (which are different levels).

Today I made the first map for one of the buildings and was testing things, when I realized, that each time I exited the building (and thus, "entered" the outdoor map) my ambient night sounds would start playing again on top of itself from the exact point it left off. The more you visit a building, the more times the sound plays on top of itself and it gets louder and sounds weird.

I know, right now you're thinking, "just put the sound under OnStart()!" but here's the thing--I have a cave the player can fall into (still part of the outdoor map technically), and I made a function so that the ambient noise fades out, and the cave is silent when you go in deeper. However, later the player will find their way back to the outdoor map (after going through several other maps), and I will want the ambient noise to resume.

Hopefully, you see my problem. Playing the sound in OnStart() works great, but only until I have to go into the cave and come back to that map later. Sorry if this was way too lengthy. Tongue

Also, I'm really good at searching for these types of things I don't know, but I keep running into weird scripting things I can't find any info on, and I feel like starting new threads is clogging up the boards. Think I should find another way to ask these questions?

Anyway, thanks so much for your help everyone! Can't wait to show off my map!
04-11-2011, 01:49 AM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#2
RE: How can I script this sound so it plays correctly?

In the Level Editor, press 5 (sound placer) and select the ambient file. Then change the radius until it ends where you want it to.

Either that, or script the sound so it fades out using StopSound("ambience", 3); //fade in 3 seconds

04-11-2011, 01:51 AM
Find
genmills Offline
Junior Member

Posts: 47
Threads: 7
Joined: Mar 2011
Reputation: 0
#3
RE: How can I script this sound so it plays correctly?

(04-11-2011, 01:51 AM)palistov Wrote: In the Level Editor, press 5 (sound placer) and select the ambient file. Then change the radius until it ends where you want it to.

Either that, or script the sound so it fades out using StopSound("ambience", 3); //fade in 3 seconds

Oh Duh! I'll fade the sound out in the OnLeave() element. Thanks so much! Sometimes it takes someone else's help to see the obvious. Wink
04-11-2011, 02:17 AM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#4
RE: How can I script this sound so it plays correctly?

Nah OnLeave() is for when you exit the entire map. Just make a collide callback function that fades the sound out when you go a certain distance into the cave. And if they backtrack, make it start the sound again (put 3 or a similar number for the fade-in effect in the function) as long as alState is -1. You will also need to make the area cover the whole cave, or else they'll pass through the area and the sound will stop for a moment, the restart (because they exited the area but are still inside the cave)

04-11-2011, 02:33 AM
Find
genmills Offline
Junior Member

Posts: 47
Threads: 7
Joined: Mar 2011
Reputation: 0
#5
RE: How can I script this sound so it plays correctly?

(04-11-2011, 02:33 AM)palistov Wrote: Nah OnLeave() is for when you exit the entire map. Just make a collide callback function that fades the sound out when you go a certain distance into the cave. And if they backtrack, make it start the sound again (put 3 or a similar number for the fade-in effect in the function) as long as alState is -1. You will also need to make the area cover the whole cave, or else they'll pass through the area and the sound will stop for a moment, the restart (because they exited the area but are still inside the cave)

But they won't be coming out the way they came in, so they wouldn't hit the trigger area to start the ambient noise again. They'll have to go through some different "levels" in the cave. I just tried using OnLeave() with fading out the sound, and always fading it in on OnEnter() and that seems to work best for my situation.
(This post was last modified: 04-11-2011, 06:34 AM by genmills.)
04-11-2011, 06:34 AM
Find




Users browsing this thread: 4 Guest(s)