[UnSolved] Every X Seconds Issue

Get help using Construct 2

Post » Tue Nov 17, 2015 4:15 am

I am having a slight issue. I have code that tests for two objects distance, Enemy and Player. If Enemy is within the distance of the Player to be able to attack I have the code set to Every X Seconds, X being the Enemies Agility Variable, call upon the attack function. The problem is this only works for which ever enemy my player walks into range of first. If I am surrounded by more then 1 enemy their Every X Second commands do not work until the first is destroyed. As this would be ok in a turn based game, I need help making it so it will run it independently, so I can be in range of various Enemy objects with different times and have it all work together.

The code I have right now is
distance(enemy.x,enemy.y,player.x,player.y) <= 800
-- Every Enemy.AGILITY seconds:: Call Attack Function

Thanks in advance guys!

(Side Note. I have tried the For Each condition hoping that would work, however it did not... Perhaps I am using it wrong?)
B
13
S
7
G
1
Posts: 31
Reputation: 1,866

Post » Tue Nov 17, 2015 4:33 am

You should use the Timer behaviour instead. It times each instance. Every X seconds is a global mechanism.
ImageImageImage
B
71
S
21
G
230
Posts: 3,688
Reputation: 128,847

Post » Tue Nov 17, 2015 5:47 am

blackhornet wrote:You should use the Timer behaviour instead. It times each instance. Every X seconds is a global mechanism.


I've tried to implement the timer behaviour and I failed... Any quick tips on how I should organize it?
B
13
S
7
G
1
Posts: 31
Reputation: 1,866

Post » Tue Nov 17, 2015 6:21 am

From the Top-down Shooter template. Give Enemy an InRange boolean and the Timer behavior. Event 9 sets up the behaviour, by distance. Event 13 does the attack.
http://www.blackhornettechnologies.com/ ... r_BHT.capx
ImageImageImage
B
71
S
21
G
230
Posts: 3,688
Reputation: 128,847

Post » Tue Nov 17, 2015 7:45 am

blackhornet wrote:From the Top-down Shooter template. Give Enemy an InRange boolean and the Timer behavior. Event 9 sets up the behaviour, by distance. Event 13 does the attack.
http://www.blackhornettechnologies.com/ ... r_BHT.capx


I copied the code exactly but it offers the same issue as Every X Seconds does. It takes the lowest timer time of both the enemies and only one of their damage gets subtracted from the health at a time. You need to kill enemy A for enemy B to attack.

Anyway to sort this out?
B
13
S
7
G
1
Posts: 31
Reputation: 1,866

Post » Tue Nov 17, 2015 8:26 am

run @Blackhornet 's capx and just work your way through it - this works as expected (nice pulse effect by the way)

If you are calling a function in your code then you may need to tell the function which enemy is expected to fire...

firstly try re-writing to not use a function and see if it works...
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,832

Post » Tue Nov 17, 2015 10:36 am

RamPackWobble wrote:run @Blackhornet 's capx and just work your way through it - this works as expected (nice pulse effect by the way)

If you are calling a function in your code then you may need to tell the function which enemy is expected to fire...

firstly try re-writing to not use a function and see if it works...


I don't understand... I deleted what I had and put it back in exactly as I had already copied blackhornets code exactly and it works now... I'll chop it up to me not paying attention to something, perhaps maybe it was the function. Either way gentlemen I am in some serious gratitude, thank you so unbelievably much!!

Have a good night!
B
13
S
7
G
1
Posts: 31
Reputation: 1,866


Return to How do I....?

Who is online

Users browsing this forum: marcinkowski, zenox98 and 26 guests