[SOLVED] How do I create 10 objects using a loop?

0 favourites
  • 8 posts
From the Asset Store
80 pieces of loopable game music, 10 game overs and 10 level complete pieces.
  • SOLVED HERE:

    ----------------

    I'm trying to create 10 objects using the Repeat loop. I have tried many different things, like

    this:

    and this (the Cooldown variable is set to 1):

    but it just keeps creating a seemingly infinite amount like this:

    I'm getting a bit frustrated, and any advice would help.

  • The system is triggering your loop every step

    you need a trigger

    ex:

    system>on start of layout

    .........>repeat 10 times............>system create sprite on layer 1 at(floor(random(100,500),100)

  • I tried this:

    and it did not work. Am I misunderstanding what you mean by "trigger"? Either way, thanks for the tip.

    ---

    EDIT: I see what you mean. I added a "Trigger once" to the first condition, and now the only problem is that the balls are all created at the same time. I'll try moving around the wait condition. Thank you for the help!

  • What granpa says is this: you can only run this once. At the moment it runs every tick.

    The events (roughtly) run top down. When it comes to the end, it starts again at the top. One time top down = 1 tick.

    So, your creation block runs once, the system starts again on top, it runs again (making more objects), it runs again and again and again, in fact it never stops.

    One way to make that event run only once is to make an 'on start of layout condition' (under system) and bring whole that creation blok as a subevent under that 'on start of layout'.

    An other way is to make a 'Trigger once while true" condition. And bring whole that creation blok as a subevent under that.

  • As grandpa and 99Instances2Go said, your event (Repeat 10 times: create obj) runs every tick, that's about 60 times per second, making an unlimited amount of objects.

    I recommend you doing this:

    System|On start of layout

    (

    Right click, add another condition or key C)

    System|Repeat 10 times

    -> Create obj

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I really appreciate the advice, but I don't want these to spawn at the start of the layout. I want to create enemies in waves, and so some waves will come after others.

    So, here is a method that works:

    When the conditions are met, create a ball, wait, create, wait, repeat.

    So now, I try replacing that SAME SPOT with "repeat", because that is what I want to repeat:

    And it does not work. Note that I DO use "trigger once". The problem is that it is not waiting. It creates the objects all at once; instead of actually completing the loop 10 times, it seems to want to do each step 10 times before moving on to the next:

    Can anyone tell me how to create things in waves without having to make a huge block of copy pasted commands like the first image in this post? Getting a bit frustrated.

  • And it does not work. Note that I DO use "trigger once". The problem is that it is not waiting. It creates the objects all at once; instead of actually completing the loop 10 times, it seems to want to do each step 10 times before moving on to the next:

    Can anyone tell me how to create things in waves without having to make a huge block of copy pasted commands like the first image in this post? Getting a bit frustrated.

    I'm wondering this, too. It seems like the Repeat loop executes the actions (10) times in a row, without going down (waiting).

  • Create a Every X seconds condition. Set X to you liking.

    Bring the creation blok as a sub under that condition. So:

    Condition every x seconds

    Sub condition repeat 10 times

    Action create the objects.

    Or, use a timer. Give any object a timer behaviour.

    Condition:

    Trigger once while true

    Action

    'any object' > start timer > X seconds > tag "wave"

    New condition

    On timer "wave"

    repeat 10 times

    action

    create the objects.

    If you only want to create 1 object each time, lose the repeat.

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