Music Button Stop

FateFighter

L1: Registered
Dec 26, 2022
32
0
I have a question, how can I set the music with the button once I have started it?
 
Last edited:
Solution
Your button's outputs will all fire at the same time when the button is damaged. You are playing it and immediately stopping it.

To debug I/O issues in the future, enable developer 2 in the console.

To fix this issue, the best solution would be to use the OnIn output to play the music, and OnOut output to stop it. Then set the button to a toggle type in the spawnflags so when activated it switches between the In and Out state. Adjust the speed and lip key values to taste, or use the Don't Move spawnflag if you don't want it to move.

Avoid using OnDamaged for button activations, and instead use OnPressed and enable the Damage Activates spawnflag. The...

worMatty

Repacking Evangelist
aa
Jul 22, 2014
1,258
999
Do you mean "How can I *stop* music?"

If you're using an ambient_generic it will accept the StopSound input if it's set as a looping sound. This entity has a lot of bugs and quirks so I encourage you to read about it on its SDK wiki page.
 

FateFighter

L1: Registered
Dec 26, 2022
32
0
Yes, that's what I'm using and it's set up ambient_generic
Képernyőfelvétel (93).png
Képernyőfelvétel (95).png
 

worMatty

Repacking Evangelist
aa
Jul 22, 2014
1,258
999
Your button's outputs will all fire at the same time when the button is damaged. You are playing it and immediately stopping it.

To debug I/O issues in the future, enable developer 2 in the console.

To fix this issue, the best solution would be to use the OnIn output to play the music, and OnOut output to stop it. Then set the button to a toggle type in the spawnflags so when activated it switches between the In and Out state. Adjust the speed and lip key values to taste, or use the Don't Move spawnflag if you don't want it to move.

Avoid using OnDamaged for button activations, and instead use OnPressed and enable the Damage Activates spawnflag. The OnPressed output can be triggered by multiple things, including the player +use key if the server has it enabled, and physical touch from the player if the Touch Activates spawnflag is enabled. It will also respond to Use or Press inputs from other entities, which is convenient. OnDamaged should be reserved for situations when you want to make the button respond to actual damage; for example by destroying it so it can't be pressed.

Tip: Add outputs to change the colour of the button to indicate its state. e.g. Red for stop and green for start. Give it a white texture like dev/reflectivity_90b and set its FX Color keyvalue to green so it spawns in looking 'off and ready'. Then add the following outputs:

OnIn > !self > Color > 255 0 0​
OnOut > !self > Color > 0 255 0​
When it's pressed in, it will turn red. When it's pressed out, it will turn green.
 
Solution