How do i apply the events to multiple instances

Get help using Construct 2

Post » Mon Sep 25, 2017 3:35 pm

dop2000 wrote: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
B
8
Posts: 37
Reputation: 383

Post » Mon Sep 25, 2017 4:34 pm

dop2000 wrote: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
B
8
Posts: 37
Reputation: 383

Post » Mon Sep 25, 2017 5:07 pm

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

Did I help to fix a problem in your game? You can buy me a cup of coffee :)
B
17
S
9
G
66
Posts: 1,004
Reputation: 36,069

Post » Wed Sep 27, 2017 5:58 pm

dop2000 wrote: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
B
8
Posts: 37
Reputation: 383

Previous

Return to How do I....?

Who is online

Users browsing this forum: Akia410 and 6 guests