How do I create sequential events?

0 favourites
  • 4 posts
From the Asset Store
Very simple code without excess options (15 events for server and 11 events for client)
  • Hi,

    i want to create a code that shows a wave on the screen that appears from below and disappear the same way. My intention would be that the x coordinate of the wave is randomly choosen. The problem is that I'm not able to code these events in a sequential way such that a new wave starts only after that the previous has completely finished its movement (so it's disappeared from the screen)

    This is the code: prntscr . com / 7dc4gw

    The condition "Random value = 0" is repeated 3 times, one for each wave

  • Not tested this, but I would break that code up into more main events (sometimes, perhaps only in bigger projects, the sub-events and sub-loops will start to act up).

    So what you can do instead is (+ = condition, > = action, - = sub layer):

    +Every 5 seconds

    +WaveIsRunning = 0

    > Set WaveIsRunning to 1

    > Set RandomValue to int(random(3))

    +RandomValue = 0

    +WaveIsRunning = 1

    > Sprite1 Set X to 1005

    > Set WaveIsRunning to 2

    +WaveIsRunning = 2

    +Trigger Once

    -+Repeat 40 times

    ->Wait WaveVelocity*loopindex seconds

    --+loopindex % 2 = 0

    -->Sprite1 Set Y to Sprite1.Y - 5

    --+loopindex % 2 = 1

    -->Sprite1 Set Y to Sprite1.Y + 5

    --+loopindex >= 40

    -->Set WaveIsRunning to 0

    Hope that helps!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi Jayjay,

    thank you very much for your reply.

    I applied your logic but using sine instead. I must say that i'm not yet satisfied with sine since it seems is not the right command to move an object vertically. What's the best option to move object from point a to point b and back in a smoothed way?

    I would like to set the program in this way since i'd like to change some input later, like cycle duration or how often the object moves. It's very important for me having a value that says when the movement is back to the origin since only then the game can move another object.

  • Hehe I was going to suggest Sine but figured I'd keep your original code. Another two ways you can try are the LiteTween plugin:

    Or using simple math and no plugins, LERP:

    So for your object you create variables:

    StartX, StartY, EndX, EndY, and T

    Then every tick set wave position to X: lerp(wave.StartX, wave.EndX, T) and Y: lerp(wave.StartY, wave.EndY, T)

    T represents a value between 0 and 1, (or 0% and 100%), so 0 for T is StartX,StartY and 1 for T is EndX,EndY, and 0.5 for T would be half-way between them.

    StartX and EndX would be the same value (the randomly picked one) based on the code you had before.

    Another variable could be used on the wave object to detect where in the cycle it is (eg: 0 = go down, 1 = at bottom, 2 = going up, 3 = at top) and a variable to say how many times it should loop (on creating set it to 3, and when cycle = 3 subtract 1 from loops and set cycle back to 0, when the loops are <= 0 then you can say "destroy" and make a new one).

    Hope that helps!

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