[SOLVED] Can't stop sounds

Guzzz

  • *
  • Posts: 517
I have a poison effect in my game. Whenever a character touches poison actor with special animation is created on top of the character and the sound is triggered. Poison lasts 3 seconds. In order to play only one sound at a time I use a simple code (see attachment). But it doesn't work. I also used drawing number to see if the game counts poison effect correctly... it doesn't :(
Here is an example of what should happen in the game:
Quote
Character #1 touches poison and sound triggered (in a loop). 1 second later character #2 touches poison and sound is triggered again. In order to play one sound at a time I stop the 1st sound and start it again. 1 second later character #2 dies but actor #1 still with the poison, so the sound should continue.
I use an actor with animation whenever someone is poisoning. So I though the easiest way to keep track on poisoning is to check when this actors dies and when it's created. However in the game when only 1 character is poisoned everything works fine, but when more than 1 character is poisoned then game can't check when the actor with poisoning animation dies. The game usually is late on 1 second. Meaning, a character dies with an actor that has poisoning animation, but sound is still playing about 1 second. The worst of it is I can see (I use drawing number of items in the list) that the game is till thinks that the actor with poisoning animation is still alive and suddenly 1 second later it goes "oh my god it did die, and switches the sound off". Weird! 

« Last Edit: September 20, 2019, 06:35:46 am by Guzzz »
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/

Luyren

  • *
  • Posts: 1831
My suggestion as an actor behavior:

When the poison is triggered for that actor, set a number attribute (Poison Ticks) to the duration of the poison in seconds * 100 (so 3 seconds is 300). If you don't want the poison effect to be refreshed if applied again, check if Poison Ticks = 0 before setting it (and doing whatever else you want to do when the poison is triggered).

In the update event, if Poison Ticks >0, decrement poison ticks by 1, then immediately after check if Poison Ticks = 0. If it is, stop your sound and do whatever else you need to stop the poison.
I have my Stencyl resources available here: https://luyren.itch.io/

Guzzz

  • *
  • Posts: 517
What I really need is to know when exactly actor dies and created. Right now it has a delay with 1 second and I don't know why.
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/

JeffreyDriver

  • *
  • Posts: 2161
I like to seperate my sounds where possible. Stencyl can handle 32(?) sound tracks, so I tend to stick my music on track 30, and then assign sound effects to their own tracks. So let's say you had poison on track 20, you'd just loop it on that track/channel and fade in/out the sound on that channel as needed.
Current Projects:
The Grand Grimoire Chronicles Episode 1 now on Kongregate!.
I always appreciate useful feedback. Thank you.
www.jeffreydriver.co.uk

Guzzz

  • *
  • Posts: 517
It's an interesting way of dealing with sounds ;)
But it still wont solve my problem. I wonder what could make this delay when "actor is created" and "actor dies" are used?
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/

Guzzz

  • *
  • Posts: 517
I tried to use code inside of dying actor in case if the block "when actor is killed" making these delays. But I still get these delays.  I wonder what can postpone the command that triggered by "killing an actor"?
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/

grmata

  • *
  • Posts: 69

Based on what I'm seeing:
Try moving the "remove 1 from poison" to above the "If" statement.
It looks like that might be the cause of your delay.

Guzzz

  • *
  • Posts: 517
At this moment my code look like that.
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/

Guzzz

  • *
  • Posts: 517
I've just had a small epiphany and I've solved the problem.
Every time when the actor (which is poison effect) is created it's starting under "when updating" lunching sound checking if the boolean in the scene's behavior is false, if so turns it true. When poison dies it stops sound and makes boolean false again. Finally!!! Hurray!
See screenshot. 
Watch my new game http://www.hitandcrash.com based on my comic strip https://www.instagram.com/hitandcrash

HeadlessD is my dungeon-crawling game on iOs and Android. Made in Stencyl. https://www.headlessd.com/