How do i apply the events to multiple instances

0 favourites
  • 14 posts
From the Asset Store
14 amazing sound files of game events like Level Ups, Level Completes, object spawn, object taking etc.
  • 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 !

  • 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:

  • 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:

    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...

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

  • > 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:

    >

    > 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

  • 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.

  • I made an improvement - each bee now has its own random timer when it turns around while "patrolling territory" <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    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.

  • I made an improvement - each bee now has its own random timer when it turns around while "patrolling territory" <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    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.

  • 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:

    since we're at it, what does this do: bee.dtp<=200 ? 0 : 150. i don't get it after 200...

  • 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

  • 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"

    Thanks a lot, you are very good at explaining

    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

  • 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

    i am running into another problem now i am trying to pin a separate hp bar over every bee. how could i do that. i tried using "for each bee" pin hpbar to bee but it pins all instances of the hp bar to one instance of a bee so i have a bee flying around with 3 hp bars that are weirdly positioned

  • Add health bar to the same container where you have your bee and bee_box.

    If you place bees manually (in editor) on your layout, then simply put a bar above each bee. You need to follow the order in which they were created though - bar with the lowest UID place over the bee with the lowest UID and so on.

    In your event sheet pin health_bar to bee_box on start of layout (the same way as bee is pinned).

    That's it.

    If you create/spawn bees during the gameplay, they will be created with the health bar, because they are in the same container. You'll only have to pin it.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Add health bar to the same container where you have your bee and bee_box.

    If you place bees manually (in editor) on your layout, then simply put a bar above each bee. You need to follow the order in which they were created though - bar with the lowest UID place over the bee with the lowest UID and so on.

    In your event sheet pin health_bar to bee_box on start of layout (the same way as bee is pinned).

    That's it.

    If you create/spawn bees during the gameplay, they will be created with the health bar, because they are in the same container. You'll only have to pin it.

    Thank you, again

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)