How do I use a loop for this condition? (closed - with solution)

0 favourites
  • 8 posts
From the Asset Store
For Adventure, Action, Heroes, Sci-fi and Action-RPG games.
  • Hey all. Hope you're doing well!

    For the below code snippet, I'm trying to:

    1. Destroy the red sprite and error text box (this works)
    2. Wait 1 second and create systemgreen text box (this works)
    3. Wait 2 seconds (this works)
    4. Then I need the code to decide if the instance variable "BuildComplete" equals 1 or 0. If 1, Set "BuildComplete" to 0 and if that value is 0, destroy the systemgreen text box. The variable is being reset to 0 but not getting destroyed.

    There may be a better way (I'm sure there is) to accomplishing #4 and I'm open to suggestions. I only want systemgreen text box to exist for 2 seconds and then be destroyed. See below for ways I've tested this. Thanks for your help and time!

  • I'm not sure I fully understand...

    I would use:

    green box ->on created: wait 2 seconds destroy

    Though if I am reading your loop correctly it does work, but it keeps creating new ones so it never loooks like they get destroyed.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm not sure I fully understand...

    I would use:

    green box ->on created: wait 2 seconds destroy

    Hey fedca! I don't see that option but it sounds like what I want. How would I add that?

  • add event

    select green boox

    search for on created

    (make sure there is no other trigger in your event already bc that makes it so you can't add other triggers unless it's an or block)

  • add event

    select green boox

    search for on created

    (make sure there is no other trigger in your event already bc that makes it so you can't add other triggers unless it's an or block)

    Found it! Thanks. I was looking under "Actions". I believe it's working, however...

    I agree with your observation on the other point about it continuously being created. How would I prevent that? Controlling that has been my latest hurdle.

  • well the problem is that the loop keeps running while the conditions are true, creating a huge amount of sprites (tbh I would assume the game to crash).

    But because I don't know the context it's hard to tell what you are trying to do.

    I think what you should do instead of a while loop is:

    if oil is overlapping Sprite

    sprite.workersassigned >2

    trigger once

    than have the actions like they are

    but remove the sub events

    and instead have the on created ...

    and a normal event like

    if sprite.BuildComplete = true

    trigger once

    wait 2 seconds set build complete to false

  • well the problem is that the loop keeps running while the conditions are true, creating a huge amount of sprites (tbh I would assume the game to crash).

    Absolutely spot on! I noticed this when testing the game play but wasn't sure how to fix it so it remained on my bug list.

    I'm testing what you provided and will report back pronto. Thank you for the guidance!

  • Success!!! Thank you very much!

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