How do I stop events from "firing" more than once (I'm not talking of "Trigger Only Once While True?

0 favourites
  • 13 posts
From the Asset Store
Change the size and position of everything without calculating anything!
  • Hello guys :)

    I keep running in this same issue, and solving it with a global variable to emulate a switch like the following doesn't stop my thirst of a solution:

    global variable = 0

    if X add 1 to global variable

    if global variable > 1 set global variable to 0

    This works fine for a very isolated case. But as soon as you want to do multiple things with it, it stops being very elegant.

    So what I want to do is this:

    But in this case, both subevents fire - resulting in it stopping itself.

    I guess the screenshot illustrates quiet good what I want to do and also why it does not work at the same time.

    If it's helpful to let you know how I want to use the solution to this problem, let me know :*

    I guess what I need is something to "break" / stop the event from continuing. But neither "Trigger Once while true" nor "signal", "wait for signal" is helping here.

    I feel like I'm missing a pretty basic understanding of how events function in Construct to solve this problem myself here. I think in c# you would just do it with a "return"? Because than the following event would not get fired.

    Any help on this would be a blasting amazing blast :****

    Thank you so much and have a great week guys!

    Chris

  • You just need to 'wait for the next tick' because both action in the same tick. So before the set cameramode to X actions, you add 'system wait 0 seconds'.

  • Add 'Else' to the second condition, so only one is ever evaluated at a time.

  • Thank you guys so much, i will try this just now!

    What I want to do with is:

    I have 1 Sun

    I have multiple Planets

    If you click on any of them, the camera focuses on them using lerp position.

    But if you click a planet while being focused on it, you return to focus the sun.

    I see if your solutions work and let you know <3

    Thanks again!!!

    Best,

    Chris

  • Add 'Else' to the second condition, so only one is ever evaluated at a time.

  • Both ways seem to work :) thanks again. I used the a little bit unelegant looking version with adding "wait 0.01 seconds" to each subevent. This way I knew what to do when expanding the code to all other planets.

    So for anyone who is interested. It is looking like this now.

    I'm open for improvements or anyone who can explain me how to achieve the same result using "else"

    Have a great productive night ;)

  • Using "else" is the proper way to deal with this particular situation. All your triggers have complementary condition, so you should just completely replace every second condition with "else".

  • Wait 0 seconds defers until the end of the current tick. So, waiting 0.01 seconds could cause trouble by having a tick or two happen before it gets back to finish those actions.

    like Magistross said, else is definitely the way to go.

    I would also put the planets in a Family so you can simplify the code down to one block:

    On Tap gesture on Planet_Trigger...

    you can give the Planet family an instance variable called PlanetNumber, and set CameraMode from that.

  • Else is fine if you have only two outcomes. 'wait 0 seconds' is used if you have more complex logic. You can't use else if you have three possible outcomes because you will find yourself with the original problem.

  • Else is fine if you have only two outcomes. 'wait 0 seconds' is used if you have more complex logic. You can't use else if you have three possible outcomes because you will find yourself with the original problem.

    Else can handle more than 2 outcomes

    and so on

  • Not true. Else is the correct solution.

    blackhornettechnologies.com/Construct3Stuff/Samples/hrisnz_SetCameraMode.zip

    Edit: ninja'd!

  • I would really discourage the use of 'Wait' for building logic like this. 'Else' is definitely the correct way to go. 'Wait' is only when you intentionally want to delay something by a period of time, such as firing a laser half a second after pressing spacebar. Since 'Wait' breaks the normal sequencing of events, if you use it in lots of places for general-purpose logic, you'll probably end up with nightmarish problems where actions and events are all running in an unpredictable order and you can't figure out how to get things in the right sequence.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You guys are a blast! Thank you so much!

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