Step 5: Tracking the train's timing

>Open Level - 5 from the levels bar.

This level has a train but it only comes through the level once. You can play the game to see for yourself.

To make more trains come, we'll check how long it's been since the last train came, and if that time is longer than the time limit we choose, we can tell the game to send another train.

>Right-click on the train tracks, and select Edit Script.

We need to set up another forever loop.

>Grab `When the level starts` (from Events), `forever`, and `if do` (both from Control Flow).

>Open Operators and drag `_=_` to connect to the `if do` block.

>Click on = and change it to >.

>Open Variables and drag `number time since last train` into the left side of the `_>_` block.

>Open Operators and drag `0` into the right side of the block. Click on 0 and type 6.

This number will be your time limit at which another train will be sent. In this example we'll use 6 seconds, but you can type whatever number you'd like in there.

>Open Events and drag `broadcast message` into the `if do` block.

>Click on "message" and type in "send train".

>Click Play and select level 5 to test your train timing. The train should keep coming back 6 seconds after it has left. When that works you can move on to the next step.

results matching ""

    No results matching ""