Call a function multiple times in a row.. possible?

0 favourites
  • 9 posts
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • Hi all,

    searched the forums, did some testing but I might be overlooking something.

    I want to call a function a bunch of times in a row, I sense it's not the way to go, but I don't know any better at the moment.

    Instead of copy pasting with 'wait x seconds' between them, is it possible to have a function run an x amount of times in a row with waits between them?

    Thanks. Regards R

  • You can use System > repeat X times for that

    Just place that on the event and you can choose how many times you want it to execute

    [quote:31ymp8do]From the manual:

    Loops

    Loops can be stopped with the Stop Loop system action.

    For

    Repeat the event a number of times, using an index variable over a range of values. The index can be retrieved with the LoopIndex system expression and passing the name of the loop.

    For Each

    For Each (ordered)

    Repeat the event once per picked instance. This only repeats for instances that have been picked by prior conditions. See how events work for more information on picking. For Each is commonly mis-used or used redundantly - actions already apply for each instance picked by conditions, so it often is simply not needed. However, if you fully understand how the event system works, it can be used to force the event to apply once per instance where the event system would not normally do that. The 'ordered' variant allows the order that the instances are iterated in to be defined by an expression. For example, ordering by Sprite.Y ascending will iterate the top instances on the screen first, moving downwards.

    Repeat

    Simply repeat the event a given number of times. This tests any conditions following it on every repeat, and if those conditions are met also runs the actions and any sub-events on every repeat.

    While

    Repeat the event until one of the other conditions in the event becomes false or a Stop loop action is used. Be careful not to create infinite loops which will cause the game to hang.

  • Anonnymitet, you missed the waiting part.

  • Or if you dont want to wait x seconds but you think function may colide with each othet you can use wait for signal.

  • Thanks guys!

    What does 'loopindex' do exactly though? I want an object to spawn (drop) bombs, but have the bombs dropped shortly after each other.

    Now it seems like the bombs are dropped exactly 1 second after each other. I want to decrease that time, I tried changing loopindex+1 to loopindex+0.2 for example but that doesn't change anything. I'm confused.

    Thanks. - R

  • Multiply: loopindex*0.2

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks, blackhornet. Did the trick.

  • What does 'loopindex' do exactly though?

    Loopindex is well, the loop index.

    If you're in the third iteration of a loop, loopindex will be equal to 3.

  • > What does 'loopindex' do exactly though?

    >

    Loopindex is well, the loop index.

    If you're in the third iteration of a loop, loopindex will be equal to 3.

    It would actually be 2 since loop indices are 0-based

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