How do i apply the events to multiple instances

Get help using Construct 2

Post » Sun Sep 24, 2017 10:39 am

So i managed to make an enemy AI that meets all my requirements (certain range makes him follow you, certain range makes him shoot, etc.) This works great on 1 instance. How can i apply this to more instances? Here's the capx: https://www.dropbox.com/s/k5bn3ywk6apnw ... .capx?dl=0
Thanks in advance !
B
8
S
1
Posts: 60
Reputation: 701

Post » Sun Sep 24, 2017 11:19 am

Use "For each bee"?
Also, you need to organize your events a bit, there are too many small events, it will very soon become hard to keep track of them.
Move some of them under "On every tick", others under "Every 0.1s", create functions etc.
Something like this:
Image
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
156
Posts: 2,202
Reputation: 82,985

Post » Sun Sep 24, 2017 11:51 am

dop2000 wrote:Use "For each bee"?
Also, you need to organize your events a bit, there are too many small events, it will very soon become hard to keep track of them.
Move some of them under "On every tick", others under "Every 0.1s", create functions etc.
Something like this:
Image
Thanks for the tips. I tried for every bee but i got anerror at the beginning. The game still worked but the enemies didn't work...
B
8
S
1
Posts: 60
Reputation: 701

Post » Sun Sep 24, 2017 12:09 pm

Well you probably moved some event that can't be executed on every tick or did something else wrong. Just try again.
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
156
Posts: 2,202
Reputation: 82,985

Post » Sun Sep 24, 2017 1:10 pm

Matei511 wrote:
dop2000 wrote:Use "For each bee"?
Also, you need to organize your events a bit, there are too many small events, it will very soon become hard to keep track of them.
Move some of them under "On every tick", others under "Every 0.1s", create functions etc.
Something like this:
Image
Thanks for the tips. I tried for every bee but i got anerror at the beginning. The game still worked but the enemies didn't work...


Matei511 you cant use the Active group that way as it would not work as intended or not work at all, as you use it with multiple instances of the same object is not like instances variables which they act independently so here once you deactivate the group you will deactivate for the whole bees and vice-versa, the Active and Deactive Group is best suited for one object like example for the player as is one object, or you can use it with multiple objects for specific things example the beginning and the end of some particular "Zone events" etc....

The reason you will have problems activating it and deactivating it is:

Because first the For Each will act for each instance independently so you gonna have the scenario where you have some Bees Angry and some not so this will a cause conflict as some they are firing Active group and some they are firing Deactive Group all at the same time so unless they are all the at same state example not Angry then it will work the deactivate the group and vice-versa and this will work as long as the trigger to deactivate groups is outside of that group because if are inside the group, once you the deactivate the group it will not be possible to activate it again as all the triggers to activate it are inside the group and the group is obviously is not active.

One thing you can do is if the bees are in a particular area or zone then you can do:

1-Before enter that zone where all the bees are, then place a dummy sprite to active the group bee controls

2-At the end of that zone where are the bees you can have another dummy to the activate the group bee controls
B
54
S
33
G
95
Posts: 435
Reputation: 53,546

Post » Sun Sep 24, 2017 3:35 pm

dop2000 wrote:Well you probably moved some event that can't be executed on every tick or did something else wrong. Just try again.

so i stopped getting the error but still the bees act exactly the same. for example every bee is supposed to face towards the player, but they all take into acount if the player has the X coorinate smaller or larger than bee 1. All bees turn around like bee 1 is supposed to.
B
8
S
1
Posts: 60
Reputation: 701

Post » Sun Sep 24, 2017 4:19 pm

I made an improvement - each bee now has its own random timer when it turns around while "patrolling territory" :)
https://www.dropbox.com/s/tvibytynqy997 ... .capx?dl=0

You can do a similar thing with bees movement speed - create an instance variable on bee or bee_box object and assign each bee a slightly different speed, at random or manually. Then use this variable when you Set Platform Speed.

Oh, and one more thing - I combined your bee and bee_box into a container.
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
156
Posts: 2,202
Reputation: 82,985

Post » Sun Sep 24, 2017 7:12 pm

dop2000 wrote:I made an improvement - each bee now has its own random timer when it turns around while "patrolling territory" :)
https://www.dropbox.com/s/tvibytynqy997 ... .capx?dl=0

You can do a similar thing with bees movement speed - create an instance variable on bee or bee_box object and assign each bee a slightly different speed, at random or manually. Then use this variable when you Set Platform Speed.

Oh, and one more thing - I combined your bee and bee_box into a container.

wow thanks a lot mate, didn't even know "timer" exited. and i used the for each wrong, i just made a for each and out all the events containing bees in. thanks a lot.
B
8
S
1
Posts: 60
Reputation: 701

Post » Sun Sep 24, 2017 7:15 pm

dop2000 wrote:Use "For each bee"?
Also, you need to organize your events a bit, there are too many small events, it will very soon become hard to keep track of them.
Move some of them under "On every tick", others under "Every 0.1s", create functions etc.
Something like this:
Image

since we're at it, what does this do: bee.dtp<=200 ? 0 : 150. i don't get it after 200... :D
B
8
S
1
Posts: 60
Reputation: 701

Post » Mon Sep 25, 2017 4:16 am

It's called ternary operator.
So you have 2 lines:
If dtp<=200 then set speed to 0
Else set speed to 150


You can write the same in one expression:
Set speed to (dtp<=200 ? 0 : 150)

dtp<=200 is a comparison statement
? means "if statement true then this value"
: means "if statement false then this value"


It's a nice little trick that can really help de-cluttering your code. You can use & and | operators , nest several ternary operators one after another and write long expressions like this:
Set speed to (dtp<=200 | bee.IsFrozen ? 0 : (bee.IsSlowedDown ? 50 : 150))
Set damage to (dtp<=100 ? 500 : (dtp<=200 ? 200 : (dtp<=300 ? 100 : (dtp<=400 ? 50 : 10))))

& means AND
| means OR
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
156
Posts: 2,202
Reputation: 82,985

Next

Return to How do I....?

Who is online

Users browsing this forum: blackhornet, inozz, TheMob000 and 1 guest