help with enemy shoot bug?

Just started using Construct 2? Post your questions here

Post » Sat Apr 19, 2014 9:19 pm

Image
Image


Okay so basically I want it to pick the enemies (bulbasaurs) that are on screen AND have instance variable "time" less than 0, then out of those, pick a random one, and set its "time" to 100. When "time" reaches 99, play it's attacking sound. When "time" reaches 25, shoot at the player, and shoot again when "time" reaches 13. time's initial value is negative and it should be negative if the enemy isn't shooting or wasn't picked. However as you can see in the video here, sometimes they play the attacking sound twice overlapping, and shoot two bullets at the exact same time. How can I fix this?

https://www.youtube.com/watch?v=jR8IkAN55Vo

The reason I am using families is because say if there's two different species of pokemon on the screen, I want a random one of any of them to set "time" to 100, but depending on the enemy, I want it to make a different sound and/or shoot a different bullet.
B
15
S
2
Posts: 103
Reputation: 1,178

Post » Sat Apr 19, 2014 9:40 pm

It has to do with how events work.

Event 8 will be tested every tick and will execute each time it is true.
So since you're changing the value of time only once every 0.01 second that renders the event 8 true twice in a row, hence playing twice the sound.

To correct it add a system condition "Trigger once while true".

It's about the same for event 9, but you may have to split it into two events to have the second shoot also happening.

Finally you might want to also look into the "Timer" behavior.

Also a note for the next time you ask for help it might be easier to provide your capx rather than a video of the issue, since it allows us to look directly in the code and potentially provide a corrected capx back. Attach it to your post.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
294
S
117
G
96
Posts: 7,311
Reputation: 71,086

Post » Sat Apr 19, 2014 9:47 pm

Kyatric wrote:It has to do with how events work.

Event 8 will be tested every tick and will execute each time it is true.
So since you're changing the value of time only once every 0.01 second that renders the event 8 true twice in a row, hence playing twice the sound.

To correct it add a system condition "Trigger once while true".

It's about the same for event 9, but you may have to split it into two events to have the second shoot also happening.

Finally you might want to also look into the "Timer" behavior.

Also a note for the next time you ask for help it might be easier to provide your capx rather than a video of the issue, since it allows us to look directly in the code and potentially provide a corrected capx back. Attach it to your post.


Thanks so much, it appears to be working right now! I am really glad it was a simple fix. But without your help I probably would not have thought of it.

The reason I posted a video was because I thought it would be helpful to SEE the bug, since it doesn't always happen very often when I play the game. I thought between that and the screenshots it would be enough. And since you were able to help me, it seems like it was.

:)
B
15
S
2
Posts: 103
Reputation: 1,178


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 1 guest