We’re introducing Meta accounts in August 2022: a new way to log into VR devices that doesn’t require a Facebook account. Learn more

LOOPS EFFECTS RANDOMLY

Let’s make a duplicate of the WaterBalloon script. We will name it LoopEffects. Bring over When World is Started, and place When Event is Received below it. Order here doesn’t actually matter, but being able to easily understand the flow of events can be very helpful. Let’s rename our new event by clicking on MyEvent, we can then choose New Event, and name it Loop. Now drag Play Sound and Play Visual Effect into the new Loop event. Then we can delete the Collision Event.
Important

  • In the next section we are going to make even better water balloons! Take your time learning these awesome new functions, and when you are ready, we’ll see you there!

PREREQUISITE READING

WATER BALLOON precedes this tutorial


At the bottom of the Events tab, you’ll find Send Event With Delay, which we will place into When Loop is Received. From Send Event With Delay, we can now choose Loop from the MyEvent drop down.

If you want a fixed rate loop, just type the delay in at the end of the codeblock. Otherwise, we are going to our Operators tab, and about halfway down, you will find Random Integer. Let’s replace the number with this codeblock. Then from our variables tab, we can create Min and Max number variables. And for now, let’s set the defaults to 10 and 60. We can now drag these number variables into their respective slots.

To start the loop, let’s duplicate Send Event With Delay into the When World is Started event. To duplicate, hover your laser pointer over the codeblock, notice how it highlights differently based on where our laser is pointed. When highlighting the full codeblock, grab and drag it up to the When World is Started event. When you see the white bar appear, press your thumbstick to the right towards duplicate. After duplicating, when you let go, the held codeblock will return to its original position.
Congratulations on building your first looping event! Let’s attach the script to our frog, and reference a splash sound and visual effect. Remember the Min and Max variables we created, you can adjust these here too. Now the frog splashes every so often. Nice work!