Trying to Make a Loop but Not Working

This forum is currently in read-only mode.
From the Asset Store
For Adventure, Action, Heroes, Sci-fi and Action-RPG games.
  • I am trying to make a simple (being retro style) shield system in my space shooter. Trying to make it that while the Hero's 2nd animation is running, a timer of Xms will eventually put the ship back to animation 1. However, all I can get it to do is come on at some point after the "BookCount" trigger has already passed one or two times. Here is the text copy of the four-step event:

    (event 70)

    + Hero: On collision between Hero and BibleDrop

    -> System: Add 1 to global variable 'BookCount'

    -> BibleDrop: Destroy

    (event 71)

    + System: Is global variable 'BookCount' Equal to 66

    -> System: Add 2000 to global variable 'Score'

    -> System: Set global variable 'BookCount' to 0

    -> Hero: Set animation frame to 2

    (event 72)

    + Hero: Animation frame Equal to 2

    (event 73)

    + System: Every 5000 milliseconds

    -> Hero: Set animation frame to 1

    However, just can not get that second animation to run after the 66 BookCount, for Xms. Once I can get this working, I can then move on to what the shields should be doing.

    Thanks for any help on this.

  • I might have this a bit wrong, thinking how loops work in C++ than in here. I was reading in the wiki and think it might be best if I remove event 72 and 73. Is there a way to make it check if the Hero's 2nd animation is running after Xms, then switch back to the 1st animation? Something like:

    If Hero animation 2 is running for 30000ms, then switch back to animation 1.

    Thanks.

  • Is (Event 73) a Sub-Event of (Event 72), or one of the Main Events?

    If it's a Main Event, then that's Your problem.

  • Just make something like:

    + Hero: animation is 2

    -> Add 1 to variable "heroShield"

    + Variable "heroShield" >= 3000

    -> Set "heroShield" to 0

    -> Hero: set animation 1

  • Shindoh, they were all sub-events of one another.

    70

    .71

    ..72

    ...73

    Now I just have...

    70

    .71

    7Soul, I see what you mean. I was thinking more complicated. Thinking something like Hero.Animation1 jazz had to be done, and that was confusing me. I did not think I could go simple like that. I will give your idea a try.

    Thanks, all.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • (event 70)

    + Hero: On collision between Hero and BibleDrop

    -> System: Add 1 to global variable 'BookCount'

    -> BibleDrop: Destroy

    (event 71)

    + System: Is global variable 'BookCount' Equal to 66

    -> System: Add 2000 to global variable 'Score'

    -> System: Set global variable 'BookCount' to 0

    -> Hero: Set animation frame to 2

    (event 72)

    + Hero: Animation frame Equal to 2

    (event 73)

    + System: Every 5000 milliseconds

    -> Hero: Set animation frame to 1

    Okay, according to my logic what should happen with this is:

    When 'BookCount' is 66 the animation frame will be changed to 2. (note animation frame is not another animation, but the second frame of the current animation)

    Then in Event 73, Every 5 seconds, we set animation frame to 1. (note again, not the animation, but the frame of the current animation)

    What we should see with this code, is the animation "frame" changing to the second frame one time, once 'BookCount' is 66, and then never change back to frame 1.

    Because Event 73 is only run every time if in the same frame/tick: "Hero Collides with BibleDrop AND BookCount = 66 AND Hero Animation Frame = 2. However in the next tick, the Event check already can't get down to Event 73, because Hero must still be colliding with Bible Drop and BookCount must be equal to 66.

    From my understanding, You should better use the Every X ms as a main Event, combined with a constantly true condition (or at least true for longer than the 'Every X ms' You entered), like a variable.

    7Souls way is a good suggestion.

  • This is what I have now...

    21

    + Hero: Value 'Shields' Equal to 0

    -> Hero: Set animation frame to 1

    22

    + Hero: Value 'Shields' Equal to 1

    -> Hero: Set animation frame to 2

    74

    + Hero: On collision between Hero and BibleDrop

    -> System: Add 1 to global variable 'BookCount'

    -> BibleDrop: Destroy

    75 (sub event of 74)

    + System: Is global variable 'BookCount' Equal to 66

    -> System: Add 2000 to global variable 'Score'

    -> System: Set global variable 'BookCount' to 0

    -> Hero: Add 1 to 'Shields'

    And this is what I have tried with more success than anything else...

    23 (sub event of 22)

    + Hero: Animation frame Equal to 2

    24 (sub event of 23)

    + System: Every 1000000 milliseconds

    -> Hero: Set 'Shields' to 0

    I have gone this high in timing (1000000 milliseconds), but the result is always the same. The "shield" (frame 2) will flash for a split second at the first 66 BookCount mark. The second time the 66 book count comes around, frame 2 stays on and never changes back.

    The idea is to have it that the shields last for, say 30 seconds. With the shields on, I will have it that the ship is, of course, invulnerable to weapon fire, but not collisions. Not sure how to deal with this yet, as I usually stick with one problem at a time.

  • if you make a simple capx and post here I can help you ^~

    I was having troubles with looping, but one day a light illuminated my brain and I saw the mechanic behind C2, so, I think everything is possible now, lol...

    See you.

  • I put up a current copy of it, stripped of about everything else, to show the current setup for the shield method I am trying to do.

    mediafire.com

    I have the book drop at a rate so I could collect and then time the shields.

  • There are two things I see up front.

    The first is, You add 1 to the 'Shields' variable, instead of setting it to 1, when 'Bookcount' = 66. And You only set the Frame to 2, if 'Shields' = 1.

    Why is this a problem? Well, if we think ahead. Then what will happen, if 'Shields' = 2? Which will happen, because You always add 1 to 'Shields' for each 66 Bookcounts. Of course right now nothing will happen if it's 2, but You never set back 'Shields' = 0.

    And You say if 'Shields' = 0 -> Set Frame to 1.

    Also the Sub-Event code for "Every 15000ms" will only run, if 'Shields' = 1.

    The next things is, the short flash You see. Why? Think about it again. When do You set Frame = 1? If 'Shields' = 1 AND "Every 15000ms".

    So this Tick let's assume 'Shields' = 1 AND "15000ms" have passed in this Tick. In this Tick Frame will be set back to 1. However the next Tick the 'Shields' = 1 Event will be checked again and what happens if 'Shields' = 1? Set Frame 2.

    It can be maddeningly frustrating at times, but stick to it and with time You will get the hang of it. You know, every beginning is hard and all good things take time. It's also important to keep a cool head and try to keep a good overview and memory in Your head of the processes going on at all times, that might be related to other.

  • Shindoh, I believe I see the mistakes you pointed out.

    23 is now (main, not a sub-event)

    + System: Every 15000 milliseconds

    24 is now (sub of 23)

    + Hero: Value 'Shields' Equal to 1

    -> Hero: Set 'Shields' to 0

    So every 15000ms AND shields is 1, set shields back to 0.

    That was it. Seems to work and shields last for 15s after books hits 66.

    I see where I kept setting values incorrectly with ADD instead of SET.

    Thank you.

    Now, onto making the shields actually block things!

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