Trigger Once While True question/issue

0 favourites
  • 10 posts
From the Asset Store
Change the size and position of everything without calculating anything!
  • Hiya,

    I'm using 3D objects as enemies. What I use is this:

    I'm not sure if I'm overlooking something simple but it's driving me crazy.

    Whenever I kill the first enemy, everything's working as expected. However, whenever I shoot the second enemy, which is a copy-paste (again, it's a 3D object) of the first enemy, it just won't execute the code at line 12.

    In the debug preview, the health of the second enemy just goes more into the minus every time it's hit by 50.

    Is it the trigger once that's causing it? I used to think putting it as a subevent would trigger it only once for that event, instead of 'forever'.

    Tagged:

  • Hiya,

    I'm using 3D objects as enemies. What I use is this:

    I'm not sure if I'm overlooking something simple but it's driving me crazy.

    Whenever I kill the first enemy, everything's working as expected. However, whenever I shoot the second enemy, which is a copy-paste (again, it's a 3D object) of the first enemy, it just won't execute the code at line 12.

    In the debug preview, the health of the second enemy just goes more into the minus every time it's hit by 50.

    Is it the trigger once that's causing it? I used to think putting it as a subevent would trigger it only once for that event, instead of 'forever'.

    try removing the trigger once as you mentioned.

    you might also want to try a

    For each 3dblock health =< 0

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • "Trigger Once" is the most misunderstood feature in Construct. The way you are using it is definitely wrong. It's supposed to be the last condition in an event and should not be used on its own.

    Also, never add Trigger Once to objects that have multiple instances. It doesn't work per instance. So if you have an event like Enemy HP<0 + Trigger Once, it will only work for the first killed enemy.

  • Hiya,

    GeorgeZaharia Yes I tried removing the trigger once, but then of course it'll repeat the actions forever, especially the audio and that's not desirable. I tried adding;

    For each Enemy

    Enemy Health =< 0

    Actions..

    However then the audio loops forever in a really unpleasant way.

    dop2000 You're right! The only way I managed to 'solve' it was to destroy the enemy once Health is =<, but that causes its own issues for example you can't keep it's state for a 'corpse' frame on the position where it died.

    Well I guess I learned something new, but how else would I approach this? I'd prefer to keep using the Health 'system' as it's a much easier way to calculate/subtract hitpoints. But I'd love to hear how it's normally done?

    I've used it a lot like this because I don't know of any other way to force an event to trigger only once per enemy. What's the alternative?

  • If you want some event to happen only once per enemy when it becomes dead, you need to use an additional flag. For example:

    Enemy Health<=0
    Enemy isDead=false
    For Each Enemy
    ...Enemy set isDead to true
    ...Audio play sound
    

    In case you are changing some property of the enemy when it becomes dead (say, switching to another animation or disabling its collisions), you can check that property instead.

    Enemy Health<=0
    Enemy animation "Dead" is NOT playing
    For Each Enemy
    ...Enemy play animation "Dead"
    ...Audio play sound
    
  • Dop2000 has given a fine answer - just wanted to add a tiny thing...

    Something I do a lot on big projects to avoid having to add lots of extra flags like "isDead" (sometimes I don't want to add a bunch of new variables for every small thing I want to do 🤷‍♂️) is to just set the health variable to a value that it can't otherwise get to through the normal gameplay process.

    Eg. If you shoot enemy & enemy health > 0: subtract 1 from enemy health

    Enemy health = 0: Play audio, set enemy health to -9999

    Now the health = 0 condition can only run once, and now I know that any enemy with health of -9999 has been marked by the system as "dead" - no extra flags needed.

  • dop2000 Thanks. In hindsight I could've thought of it myself, but the learning is the most important thing.

    One thing though; I am not able to specifically test a boolean to false. There's only 'Is boolean instance variable set' and if I use that then it doesn't work. When I use a instance variable number (0 and 1), it does work. Was there something I'm missing? It's value box wasn't ticked so it should be initially false.

    mikehive That could work, but not if you had for example different enemies shooting at eachother with different hit power. Turret 1 does 30 damage to enemy, where enemy health = 100. At one point it will be -20 and the event won't run correctly because it was never exactly at 0.

  • Yeah, with booleans you need to use "Is boolean set" conditions. An integer variable with 0/1 values will work too, in fact I prefer it to boolean in Construct.

    Regarding your question to mikehive - you can add a couple of conditions:

    Enemy Health <= 0
    Enemy Health > -1000
    ....Enemy set health to -9999
    
  • Yes, or just set it to something else that doesn't cause problems with your existing events. Set it to +999999 or whatever.

    It doesn't matter either way - dop2000's answer will work fine for you. I just wanted to add that sometimes when I'm doing a lot of complicated work in the event sheet and am in a flow state, I don't always want to go to the layout view or the project bar, find the right object, and add another instance variable to it - it breaks my concentration - sometimes it's just faster to use the variables you already have to hand to get something done quickly :)

  • here is my solution, il read above what you where trying to achieve. but this is what i meant with the for each.

    testing c3 sorry for the long song.. couldn't find a FX sound lmao.

    mikehive That could work, but not if you had for example different enemies shooting at each other with different hit power. Turret 1 does 30 damage to enemy, where enemy health = 100. At one point it will be -20 and the event won't run correctly because it was never exactly at 0.

    it doesn't matter if the damage taken is 1 or 99 cause your condition is less or equal to zero.. the object should be destroyed. or call a function/event that does something then destroy that object. otherwise the song will loop forever as that less or equal will always be true forever as long as that 1 character is still on screen/dead or with health under zero or equal to zero.

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