Page 1 of 1

### How do I create sequential events?

Posted: Thu Jun 04, 2015 3:36 pm
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

### Re: How do I create sequential events?

Posted: Fri Jun 05, 2015 10:07 am
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!

### Re: How do I create sequential events?

Posted: Sat Jun 06, 2015 1:47 pm
Hi Jayjay,

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.

### Re: How do I create sequential events?

Posted: Sat Jun 06, 2015 10:47 pm
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: viewtopic.php?t=70700&start=0#355295

Or using simple math and no plugins, LERP:

what-is-lerp-2-minute-tutorial-for-the-non-math_t60509

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!