0 Favourites

How do I break?

  • I have an event that switches a state from active true to active false, but also sets another object to active true which sets the first to active true so I just get a loop and nothing happens. I'm probably not explaining well but basically I have something like this:

    OnEnterPressed(){

    if (object1.active = true)

    object1.active = false

    object2.active = true

    if(object2.active = true)

    object1.active = true

    object2.active = false

    }

    What I want to do as add a break so it only checks one if each time it is pressed.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • I'm not quite sure what you want to do, but I have some idea. Can you fix it with an else statement?

    I think the best solution is to use the System.TriggerOnceWhileTrue condition, which means that each object will only try and change the other when it is first activated. Then Maybe some kind of cooldown timer, depending on what you want to do.

  • so you want to a toggle switch.

    I do this all the time, depending on what triggers it, it should be fine as is. If this code is in a "onclick" event, it's only going through it once, so you can just have 2 "ifs".

    if it's in an area where it's getting triggered all the time, then you would just use an Else statement.

    It all depends in what is triggering it.

  • I'm not quite sure what you want to do, but I have some idea. Can you fix it with an else statement?

    I think the best solution is to use the System.TriggerOnceWhileTrue condition, which means that each object will only try and change the other when it is first activated. Then Maybe some kind of cooldown timer, depending on what you want to do.

    The trigger once seems like it'll help my enter press not be continuously evaluated, which is helpful, but it doesn't seem to help my main problem. I will attach a screenshot of my events for clarity.

    As you can see I'm trying to switch the visibility of two sprites if one is active it's visible and two invisible if two is active one should be invisible and 2 should be visible. Right now if I delete the second if then it works but there's no way to get back. I'm trying to set up a toggle on enter pressed, if that makes any sense.

  • Try this:

    OnEnterPressed(){

    if (object1.active = true)

    object1.active = false

    object2.active = true

    else

    object1.active = true

    object2.active = false

    }

    The system else event is used to create these toggle type of events. Since object2 is only set active with object1 is inactive, the else statement should work fine.

  • Try this:

    OnEnterPressed(){

    if (object1.active = true)

    object1.active = false

    object2.active = true

    else

    object1.active = true

    object2.active = false

    }

    The system else event is used to create these toggle type of events. Since object2 is only set active with object1 is inactive, the else statement should work fine.

    Thanks! Else worked.

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