asynchronous functions in loops

0 favourites
  • 10 posts
From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies.
  • Why it doesn't work in loops?

    c3p: dropbox.com/s/pkrmjn7erstfowg/asyncfunc.c3p

    What i'm trying.

    Run CreateTop

    ->(First loop)

    -->wait 0

    -->create sprite

    -->Run CreateBottom

    (Loop 2x)

    --->wait 0

    --->create sprite

    --->wait 1

    --->create sprite

    Run CreateTop

    ->(Second loop)

    repeat like this

  • Try to change the variable "loop" in the first function to static too.

    And you can remove "Wait for previous action", it has no effect there.

  • Try to change the variable "loop" in the first function to static too.

    And you can remove "Wait for previous action", it has no effect there.

    This codes creating total objects as expected but i want it ordered.

    I want like this;

    Run CreateTop

    ->(First loop)

    -->wait 0

    -->create sprite

    -->Run CreateBottom

    (Loop 2x)

    --->wait 0

    --->create sprite

    --->wait 1

    --->create sprite

    Run CreateTop

    ->(Second loop)

    repeat like this

  • We really need a system timer for this kind of stuff.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • So you need to create 1 sprite at the top, then 2 at the bottom, then repeat? And a pause between each sprite?

    Try this:

  • dop2000

    Thanks, i see you just calculate time for 2. loop with wait 3*loopindex. But if we don't know how many times need for 2. function. I think this is not good example for that but i'm trying to get this.

    Also first local value don't need to be static, it doesn't reset 0 until function finish.

  • Thx, i got it. I hope Ashley will support that feature in loops too. JSON, Array etc. operations will be easier for kind of this issues.

  • EDIT: just saw dop2000's version - I like the way he did it better than mine! :)

    OhhBaby in your first post you asked why it isn't working. I tried your file, and had it log when it created each item (the tickcount at the time it created a sprite).

    I would argue that it is doing exactly what you are asking it to do.

    in the first function it waits half a second to create each top sprite - and they are created at 30 ticks, 60, 90, 120, and 150 ticks.

    after each top sprite is created you call the bottom function and have it wait 1 second before creating each bottom sprite.

    the bottom sprites for the first top sprite are created at 90 and 150 ticks.

    the bottom sprites for the second top sprite are created at 120 and 180 ticks

    the bottom sprites for the third top sprite are created at 150 and 210 ticks

    the bottom sprites for the fourth top sprite are created at 180 and 240 ticks

    the bottom sprites for the fifth top sprite are created at 210 and 270 ticks

    so, maybe that isn't what you had in mind, but it is waiting the amount of time you ask it to. You end up with a couple sprites created at 90 and 120 ticks, 3 at 150 ticks, 2 at 180 ticks, etc.

    I am guessing you wanted it to wait until both bottom sprites were created before it went on to create the second top sprite. You added the "wait for previous actions to complete" after calling the bottom function but that would only affect actions added immediately after that point - it doesn't prevent the loop above it from continuing to run.

    I made a sample how I would probably do it... The CreateBottom function hasn't changed, but the CreateTop had to be done differently.

    https://www.rieperts.com/games/forum/asyncLoop.c3p

  • If the game has many things to load and it takes longer than usual to load wouldn't that affect the Spawn as you use the Wait as it could delay the waits?

    I will use Timers to be accurate at all the times without any delays, to be on the safe side.

    https://www.dropbox.com/s/784qwx5jtvj1bkm/spawn%20in%20time.capx?dl=0

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