cant get sound to work on animated decoration

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Rabbitslayer1
Posts: 12
Joined: Sun Dec 15, 2024 12:05 pm
Preferred Pronouns: He/Him

cant get sound to work on animated decoration

Post by Rabbitslayer1 »

How do you get sound to play on an actor with animations. IF I dont put spound in animation works fine .put sound in it plays sound does one frame then plays sound again.
this is is my code with the sound

Code: Select all

class TOCT : Actor
{
 Default
 {
 Height 70;
 Radius 40;
 Scale .5;
 }
 States
 {
 Spawn:
 TOCT A       950 A_StartSound("FIRET/Loop"); // Notice the duration of this state is 35 tics, which equals one second.
 TOCT A 4;   
 TOCT B 4;
 TOCT C 4;
 TOCT D 4;
 TOCT E 4;
 TOCT F 4;
 TOCT G 4;
 Loop;
  }
  }
Last edited by Rabbitslayer1 on Thu Mar 27, 2025 8:01 pm, edited 1 time in total.
User avatar
SanyaWaffles
Posts: 871
Joined: Thu Apr 25, 2013 12:21 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Windows 11 for the Motorola Powerstack II
Graphics Processor: nVidia with Vulkan support
Location: The Corn Fields
Contact:

Re: cant get sound to work on animated decoration

Post by SanyaWaffles »

add NoDelay to the first frame.
User avatar
Rabbitslayer1
Posts: 12
Joined: Sun Dec 15, 2024 12:05 pm
Preferred Pronouns: He/Him

Re: cant get sound to work on animated decoration

Post by Rabbitslayer1 »

Didnt make any difference.It still plays sound then one or two frames of the animation.
User avatar
Rabbitslayer1
Posts: 12
Joined: Sun Dec 15, 2024 12:05 pm
Preferred Pronouns: He/Him

Re: cant get sound to work on animated decoration

Post by Rabbitslayer1 »

I got it to work in decorate but still wont work in zscript
User avatar
Rabbitslayer1
Posts: 12
Joined: Sun Dec 15, 2024 12:05 pm
Preferred Pronouns: He/Him

Re: cant get sound to work on animated decoration

Post by Rabbitslayer1 »

I still havnt got it to work in zscript.So i used decorate Instead
User avatar
Enjay
 
 
Posts: 27158
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: cant get sound to work on animated decoration

Post by Enjay »

I have to admit, I'm a bit confused by your code.

Your comment says that the frame lasts 35 tics but it is set to appear for 950.
Also, the code loops - it it really your intention to have the actor appear on one frame for 950, and then quickly go through ABCDEFG at 4 per frame and then go back to the long duration frame?

I also notice that the sound is called fire/loop. You may be interested to know that you can set a sound to be played as a loop with A_StartSound rather than relying on the animation to loop and restart the sound when it gets back to the first frame.

So, I don't know if this is what you are looking for, but it works (obviously I have changed the sprite and sound names to work with Doom2.wad without any additional resources):

Code: Select all

class TOCT : Actor
{
	Default
	{
		Height 70;
		Radius 40;
		Scale .5;
	}

	States
	{
		Spawn:
		POSS A 0 nodelay A_StartSound("brain/spit", CHAN_BODY, CHANF_LOOPING, 1.0, ATTN_NORM, 0, 0);
		POSS A 35;
		POSS A 4;   
		POSS B 4;
		POSS C 4;
		POSS D 4;
		POSS E 4;
		POSS F 4;
		POSS G 4;
		GoTo Spawn+1;
	}
}
User avatar
Rabbitslayer1
Posts: 12
Joined: Sun Dec 15, 2024 12:05 pm
Preferred Pronouns: He/Him

Re: cant get sound to work on animated decoration

Post by Rabbitslayer1 »

I was trying to get the sound to play to end before it looped if i tied a lower number it didnt even if i tried useing 4 for animation the sound only played 1 sec but the animations were still screwed up
User avatar
Enjay
 
 
Posts: 27158
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: cant get sound to work on animated decoration

Post by Enjay »

So you want it to play a sound to completion on one frame, then go through an animation, restart and do the same thing over and over? Is that correct?

Or play the sound once while the actor goes through its animation, but finish when the animation is about to restart again?



If the animation loops before the sound is complete, unless you set it to do otherwise, it will loop and the new instance of the sound will override the first instance (i.e. constantly making the sound restart when it gets to the first frame). Perhaps that was a problem?


Whatever it is you are trying to achieve, I think it is pretty simple - so it will definitely be doable if you still want it in ZScript. If you are happy with the DECORATE version, then that's fine too of course.
(If you show your DECORATE code (or even share the whole actor - sprites, sounds and code), it might give me a chance to figure out exactly what it is you are trying to do. Again, if you are happy with the DECORATE version, then there is no need.)
User avatar
phantombeta
Posts: 2184
Joined: Thu May 02, 2013 1:27 am
Operating System Version (Optional): Windows 10
Graphics Processor: nVidia with Vulkan support
Location: Brazil

Re: cant get sound to work on animated decoration

Post by phantombeta »

If I'm understanding correctly, I think they want it so the sound loops correctly without overlapping itself. In which case, you can simply do this:

Code: Select all

 States
 {
 Spawn:
 TNT1 A 0 NoDelay A_StartSound("FIRET/Loop", flags: CHANF_LOOP);
 Animation:
 TOCT ABCDEFG 4;
 Loop;
  }
User avatar
Rabbitslayer1
Posts: 12
Joined: Sun Dec 15, 2024 12:05 pm
Preferred Pronouns: He/Him

Re: cant get sound to work on animated decoration

Post by Rabbitslayer1 »

I want the sound to play continously like an ambient sound

Code: Select all

ACTOR TOCT  14467
{
	//$Title TOCT Torch
	//$IsDecoration
	//$NotAngled
	//$Arg0 Play sound
	//$Arg0Default 1
	//$Arg0Type 11
	//$Arg0Enum falsetrue
	Game Doom
	Height 90
	Radius 25
	Alpha 0.7
	Scale 0.4
		
	+SOLID
	+MOVEWITHSECTOR

		States
		{
			Spawn:
			   	TOCT A 650 NoDelay A_JumpIf (args[0] == 1, "Sound")
				goto Animate
			Sound:
				TOCT A 0 A_PlaySound("FIRET/Loop", CHAN_6, 1, TRUE)
			Animate:
				 TOCT ABCDEFG 4 Bright Light("TOCT")
				Loop
		}
}
https://imgur.com/O6IbJga
User avatar
Enjay
 
 
Posts: 27158
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: cant get sound to work on animated decoration

Post by Enjay »

What phantombeta and I posted are two slightly different ways to do the same thing. e.g. if you load up my example in a zscript file and summon the actor, you will see a half-size zombie going through the animation and you will hear the boss/spit sound looping continuously (like an ambient sound).

phantombeta's code does basically the same thing. Our animation timings will be different though, because I set the first frame to be 35 tics long, because I thought that was what was wanted.


I notice that your code requires the 0 argument on the thing to be set to 1 before sound can be heard (fair enough) but just a quick check - you have actually set the argument in the map right? If you haven't, it won't make a sound.

It's also worth pointing out that you are using A_PlaySound. This has been deprecated. It is better to use A_StartSound (as per mine and phantombeta's examples).

I'm also still not sure why the first spawn frame has such a long duration. It will be sitting there not animating for about 18 seconds before the animation starts. Is that what you want?

[edit]Having now seen the image, you just want a torch that sits there making a torch crackling sound? If so, then, phantombeta's code will do it just fine. If you want to incorporate the option of having the torch be silent, that's a reasonably easy addition - along the lines of what you have already done.

Something like this would probably do it:

Code: Select all

class TOCT : Actor
{
	Default
	{
		Height 70;
		Radius 40;
		Scale .5;
	}

	States
	{
		Spawn:
		TOCT A 0 nodelay A_JumpIf(args[0] == 1, "Animation");
		TOCT A 0 A_StartSound("FIRET/Loop", CHAN_BODY, CHANF_LOOPING, 1.0, ATTN_NORM, 0, 0);
		Animation:
		TOCT ABCDEFG 4; 
		Loop;
	}
}
(Variations of the above are possible)

I haven't tested it, but I think that should check arg0 and if it is 1, it will jump to the animation without playing the sound. If arg0 is anything else, it should also start the sound and then progress on to the animation. The sound should keep playing while the animation just loops over and over.
User avatar
Enjay
 
 
Posts: 27158
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: cant get sound to work on animated decoration

Post by Enjay »

I just realised that I gave my example code the reverse logic to your code.

In your code, the sound only plays if arg0 is 1.
In my code the sound always plays unless arg0 is 1.

:oops:

If what I wrote isn't suitable, it's easy enough to reconfigure the logic.
User avatar
Rabbitslayer1
Posts: 12
Joined: Sun Dec 15, 2024 12:05 pm
Preferred Pronouns: He/Him

Re: cant get sound to work on animated decoration

Post by Rabbitslayer1 »

https://www.dropbox.com/scl/fo/gcvu3e16 ... 76mxt&dl=0
Heres a WAD with everything To show what i wanted to do in zscript.
User avatar
Enjay
 
 
Posts: 27158
Joined: Tue Jul 15, 2003 4:58 pm
Location: Scotland
Contact:

Re: cant get sound to work on animated decoration

Post by Enjay »

And here it is doing much the same in ZScript:
https://aspectsweb.co.uk/enjay/TempStuff/TOCT2.zip

As with your one, this only makes a sound when arg0 is set to 1. Otherwise it appears as a silent torch.

If you just type summon TOCT at the console, the torch will appear, but it will be silent. This is because it has not been given an arg0 of 1 when you summon it. (Perhaps that was the original problem?)

If that's not what you want, you can do away with the whole arg0 stuff and A_jump... entirely.


You'll also notice that I added a MAPINFO lump. In ZScript, you don't put the Editor numbers in the ZScript code, they go in MAPINFO.

If it's of interest at all, it is also possible to set up the torch as a switchable decoration where you can activate/deactive the torch and have it lit/unlit accordingly.
User avatar
Rabbitslayer1
Posts: 12
Joined: Sun Dec 15, 2024 12:05 pm
Preferred Pronouns: He/Him

Re: cant get sound to work on animated decoration

Post by Rabbitslayer1 »

Thank you for all the help. :D :D :D
Post Reply

Return to “Scripting”