Page 1 of 2

Stopping sound before time?

PostPosted: Fri Jan 06, 2006 2:25 am
by Diana Kennedy
Hi to all,

Is there a way to stop sound playing before it is finished?

In my game, I have an activation event that makes a wild animal changing its path and animation (from normal walking to galopping away) when the player clicks on the "make hunter take aim" area. It also causes a hoofbeat sound start playing. The soundclip is just as long that it covers all the way of the animal to flee out out of the view. Works really cool!
But when the hunter shoots his arrow and takes the animal down...the hoofbeat continues. Is there a was to make the hoofbeat stop when the animal is killed?

Diana

PostPosted: Fri Jan 06, 2006 7:20 pm
by Novice
I also just noticed that there is no stop sound function. So i repeat the question.

PostPosted: Fri Jan 06, 2006 7:31 pm
by makslane
Use the stopSound function.
Look this thread:

http://game-editor.com/forum/viewtopic. ... =stopsound

PostPosted: Fri Jan 06, 2006 11:06 pm
by Diana Kennedy
makslane wrote:Use the stopSound function.
Look this thread:

http://game-editor.com/forum/viewtopic. ... =stopsound



Eww, it deals with variables and so on. Isn't there a step by step tutorial with a working example? Where do I create a variable? in global code or in the script editor of the given actor (The animal)? I tried to "add variable" in the animal actor, it asks me questions like "channel" and so on, I have no idea what that means. The sound file in question names horse-galopp.wav. The actor is tarpan. So ca I have a clue where to write in what?

PostPosted: Sat Jan 07, 2006 1:18 am
by makslane
Each sound in the game are played in a channel.
The PlaySound function returns the channel used to play the sound.

So, you must use the returned channel to control the sound (stopSound, setVolume, setPan)

You can create the variable with the "Variables" button in the "Script Editor"

PostPosted: Sat Jan 07, 2006 2:11 pm
by Diana Kennedy
makslane wrote:Each sound in the game are played in a channel.
The PlaySound function returns the channel used to play the sound.

So, you must use the returned channel to control the sound (stopSound, setVolume, setPan)


And how do I know which channel? Sorry, I didn't get that... :( Again, isn't there a working tutorial somewhere?

You can create the variable with the "Variables" button in the "Script Editor"


again, in the global script editor or in the script editor of the actor?

This would be strong wish for next versions of GE: Simply ad a "stop sound" action in the action lists, because this variables / channel thing is way too difficult for newbies like me. :cry:

PostPosted: Sat Jan 07, 2006 6:05 pm
by Game A Gogo
Diana Kennedy wrote:again, in the global script editor or in the script editor of the actor?


in the script editor, dont worry, you will get better soon, it took me 2 years befor I knew what was a Variable in GE, lol.

PostPosted: Sat Jan 07, 2006 9:42 pm
by Diana Kennedy
Game a Gogo wrote:
Diana Kennedy wrote:again, in the global script editor or in the script editor of the actor?


in the script editor,



Game...please.... in the script editor of THE ACTOR or in the GLOBAL SCRIPT EDITOR? :cry:

dont worry, you will get better soon, it took me 2 years befor I knew what was a Variable in GE, lol.


Yeah, then it will take me probably two centuries.. :wink:

PostPosted: Sat Jan 07, 2006 10:04 pm
by Joshua Worth
Game a Gogo wrote:in the script editor, dont worry, you will get better soon, it took me 2 years befor I knew what was a Variable in GE, lol.

Once you learn it in GE you know it in pretty much everythng.

If you know algebra you should know how to use variables...

PostPosted: Sat Jan 07, 2006 11:17 pm
by Diana Kennedy
Joshua Worth wrote:
If you know algebra you should know how to use variables...


I guess so. Well, I do NOT know Algebra. I managed to sleep through those classes during entire high school and college. maybe if back then I knew that there once would be a GE, I would have tried to get a notion or two of that nasty stuff.

:oops:

PostPosted: Sun Jan 08, 2006 2:53 pm
by Game A Gogo
its in the actor scrotp editor, i can tell you a short ting about Var...

Var=Variable

A variable is a number or text that can be change and stored, a Var is use to "save" the pehipherique* of a state, but only for the time that the ged\exe\dat is open.

(* if you dant know what that meens, i dont ether, it make me look more smarther :wink: *)

PostPosted: Wed Jan 11, 2006 6:17 am
by Diana Kennedy
Ehm...Does anybody have some further help for this problem? I am really stuck with that and controlling sounds is quite of vital in my actual project. I would greatly apreaciate...

PostPosted: Wed Jan 11, 2006 11:13 am
by twobob
For each sound file create a Global variable with the "Variables" button in the "Script Editor". Name it (i.e firesound1) and choose integer and global so that you can use this variable anywhere in your game script to stop the sound/music.

In your script where you have placed your code to play the sound/music
i.e PlaySound2("data/Tock.wav", 1.000000, 1, 0.000000);
You place in front of this the global variable that you created.
For example:
firesound1 = PlaySound2("data/Tock.wav", 1.000000, 1, 0.000000);

When you want to stop the sound, in the script editor of the actor that controls your game, place the following code:-
stopSound(firesound1);
This will now stop any sound/music playing

PostPosted: Sat Jan 14, 2006 7:28 am
by Diana Kennedy
Twobob, Thank again for your assistance. Unfortunately, it did not work. (I probably messed up). So here is what I did:

twobob wrote:For each sound file create a Global variable with the "Variables" button in the "Script Editor". Name it (i.e firesound1) and choose integer and global so that you can use this variable anywhere in your game script to stop the sound/music.


Done. I called it galopp1

In your script where you have placed your code to play the sound/music


It wasn't done with a script. I used the "activation event". (When player clicks on the filled regions, horse flees in galop, changing path and animation - and sound)
Okay, so now I removed the play sound action of this activation event and instead of that used "activation event"-> script editor->
Code: Select all
galopp1 = PlaySound2("data/horse-galop.wav", 1.000000, 1, 0.000000);


(By the way, for what does the 1.00000 and so on stand for?)

Anyhow: It did not work. No sound is played now and even the other actions related to this activation event, changing path and animation do not work anymore. The scrtipt seems to have killed all actions on that particular activation event. (Altough that they are still in the list)

When you want to stop the sound, in the script editor of the actor that controls your game, place the following code:-
stopSound(firesound1);
This will now stop any sound/music playing


What is meant by "actor that controls your game"? I worked in the actor that received the events and had to play the sound. (the wild horse)

Here is a screenshot for better understanding. The filled wires are the "aiming points." aim1, aim2 ,aim3 and so on. When clickling on it, an arrow actor is cretated, the hunter changes animation, the horse runs away and the sound of galop should be played. when right ctrl is clicked, the arrow is shot (following its path) and if horse crosses that path: collision, horse falls down, gallop-sound should stop.

I tried out your advice on one aiming point. Curious - the sound works not anymore also on the other aiming-points, too. But there, I didn't change anything.

Image

PostPosted: Sat Jan 14, 2006 10:11 am
by twobob
In your script, are you using the variables/functions button at the bottom of the script editor to add the sound – this allows you to set the volume/loop/pan control, and you should also hear the sound playing when you choose the file in the pop up box. This will also place the correct path to your sound file automatically.

The numbers in the enclosed brackets in the script are the volume/loop/pan which you alter in the pop up box.

To view the script reference for functions and what they do, in game editor click on help then documentation, on the left of the page choose scripting, and at the bottom of this page click on script reference.