In our scoreboard, we need to create a display loop. Bring over When World is Started, and When Event is Received. Change MyEvent to loop. Then place the Send Event To Object codeblock in the World Start event. Select Loop from the MyEvent drop down. Then place Send Event With Delay into Loop, and set it to Loop as well.
On our Variables tab, create a new variable called DisplayMe. Which will be a string. Bring over SetTo from the Values tab, and place a string input on the right. Then put DisplayMe on the left. Let’s type “Splash Count:” into the string input, and we now have a title for our scoreboard. From Actions, bring over the Display Text codeblock. We will leave this as self, as our script will run on a text gizmo. Then replace the string input with DisplayMe.
PREREQUISITE READING
TRACKING PLAYERS IN THE WORLD precedes this tutorial
Now that we have the display loop completed, we need to create a While Loop, which will allow us to add all of the player names and scores to the DisplayMe string. While loops are extremely powerful and allow you to quickly iterate through a list. Please note that While, requires a finite number of iterations, and can break if there are too many or a lot of actions running in each iteration.
The first thing we need to do is create a new variable named Iterator, this is a number. From Values, place SetTo above the display text codeblock, putting Iterator on the left. And at the bottom of the Operators tab, grab the Length of List codeblock, placing it on the right. We can then put in our CurrentPlayers list.
Place the While codeblock between SetTo and Display, and then bring the greater than symbol over. We will place Iterator on the left, and zero on the right. Now our while loop will only run, when the iterator is greater than zero. Indent a SetTo codeblock under While, placing Iterator on the left, and a minus symbol on the right. We can put Iterator in the “A” slot, and a number input, set to one, in “B.” This will cycle us through the entire list of players. It is important to note that the position’s available in the list are one less than the length. In other words, a list starts with zero being the first item, and length minus one being the last item. That said, the next few codeblocks will go below the SetTo codeblock and will also be indented into the while loop.
From the Values tab, bring over three more SetTo codeblocks. We will then create a new player variable called CurrentPlayer, place this in the left side of the first SetTo. Then from Operators, we will grab Get Item From List, and place this on the right side. Placing Iterator into the left side of this codeblock, and our list variable on the right. Now we have saved the current player as a variable, rather than having to always call the Get Item From List codeblock.
On the Operators tab, grab a Plus symbol to put on the right of the remaining SetTo codeblocks, and an additional plus symbol on the right of each of those pluses. We will then put DisplayMe on the left side of the SetTo, as well as the far left of each plus symbol. This allows us to add onto the DisplayMe variable.
Bring a String input into both of the remaining “A” slots. Type in “<br>” into the first String. And “: “, into the second string.
From Operators, under Player, place the Name of Player codeblock into the “B” slot after the break. Placing the CurrentPlayer variable inside of it.
Then from Values, place Variable as String in the last “B” slot, and place the Get Player Variable inside of it. We can then fill it out, selecting Score from the drop down, and putting CurrentPlayer in the player slot.
Now every player will have their own line under Splash Count, that displays their name and score. Great work! We can test this out by attaching the script to a Text Gizmo, and entering the world. I recommend we place this text on a solid background to create a proper scoreboard. Very nice work!