Trigger Once Conditions Does Not Work, Why ?

Get help using Construct 2

Post » Sun Feb 12, 2017 10:05 pm

Message: deropke2 can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
https://gyazo.com/befbfc33e9e849a7f6fbaa13bf048ea1

Basically it keep spawning health every tick and the game drops to 1 fps in like 30 seconds

Saddly can't post screenshots of code but it's like :

For each enemy
trigger only once = Spawn healthbar
Last edited by deropke2 on Sun Feb 12, 2017 10:24 pm, edited 3 times in total.
B
5
S
1
Posts: 28
Reputation: 391

Post » Sun Feb 12, 2017 10:15 pm

your code will run approx. 60 times a second.

you are creating 60 health bars every second for each enemy

try "on start of layout > for each enemy" instead
...
B
42
S
21
G
7
Posts: 260
Reputation: 7,683

Post » Sun Feb 12, 2017 10:21 pm

NetOne wrote:your code will run approx. 60 times a second.

you are creating 60 health bars every second for each enemy

try "on start of layout > for each enemy" instead


This only spawns health for the first enemy
B
5
S
1
Posts: 28
Reputation: 391

Post » Sun Feb 12, 2017 10:47 pm

You could do:

Enemy: On created - Create health bar

Which will run once per enemy
Vote for all the Construct 2 games on Steam Greenlight - Find them here
B
32
S
9
G
7
Posts: 444
Reputation: 6,731

Post » Sun Feb 12, 2017 11:05 pm

deropke2 wrote:This only spawns health for the first enemy


Well, no. Not really.
It is 'Trigger once while true' not 'Trigger once'.

It triggers once when the event containing that 'Trigger once while true' is true.
When it is the only condition in that event it will trigger only that one time ... that it self runs as being true.
And one would think that this event (containing no more conditions) cant be set to false again (actually resetting the trigger).

That is true when it is a root event.

But, mind the logic, this true/false has (as every variable does) a scope.
(read about scopes --->https://www.scirra.com/manual/83/variables)

Is it a root event, then the scope is the big tick loop.

Bring it in a sub loop, and the scope is that loop. It will actually reset each iteration.

I know that this make it worthless in a loop.
B
33
S
18
G
27
Posts: 2,436
Reputation: 20,336

Post » Sun Feb 12, 2017 11:19 pm

Come to think of it the easiest way is to put the health bar in a container with the enemy.

Then it will always get created and destroyed with the enemy. (and even picked) no extra code needed

This is a super feature of Construct 2
...
B
42
S
21
G
7
Posts: 260
Reputation: 7,683

Post » Sun Feb 12, 2017 11:51 pm

OddConfection wrote:You could do:

Enemy: On created - Create health bar

Which will run once per enemy


Thanks this has solved my problem
B
5
S
1
Posts: 28
Reputation: 391

Post » Mon Feb 13, 2017 7:06 am

as i can see... you can use the container too so that on every spawn or create a monster the health bar automatically created too :D i hope it helped :D
B
79
S
31
G
7
Posts: 148
Reputation: 9,179


Return to How do I....?

Who is online

Users browsing this forum: Lancifer, NyxoGe and 7 guests