Let’s assume that the fundamentals of the project are already in place: The main actor, platforms, treasure, and logic that considers user input and dictates movement. (These will be covered in more detail in subsequent tutorials)
However, while the treasure has already been configured to disappear upon colliding with the primary actor (henceforth referred to as “the Hero”), as of yet it has no behaviors in place to track how much has been picked up by the Hero.
Adding a Score…
To add in this feature, let’s start out by creating a new game attribute. To do this, select the attributes tab and click the plus sign, while editing a scene. This attribute will be used to keep track of the total score, so we’ll keep it simple by selecting integer as the type. Now, rename the attribute by double clicking on the default current name of “New Attribute” and change it to “Total Score”.
In this particular example we will soon be making the value of this attribute visible to players – however the actual name of the attribute will not be, so it’s a always good idea to be short but descriptive when coming up with attribute names.
With our newly created attribute available, all we need now is to change the logic governing treasure actors such that they trigger an update to the Total Score attribute each time the Hero scoops up a fresh piece of loot.
Pictured below is a very clear-cut method of setting up this logic. As your understanding of the GameSalad Creator improves you’ll find that your behavior combinations are often much more complex than this, but it’s important to remember that at times, simpler is better.
As you can see, we’ve added a simple Change Attribute behavior, so that when the rule triggers (ie, the Hero reaches the treasure), our attribute is increased by 100 before the treasure is removed from the scene.
Adding a Display…
Now when the Hero picks up loot, the game keeps track of it. The only trouble now is that while the game may know how much treasure has been picked up, as it stands the player does not. Which brings us to the second part of this tutorial: reporting.
The heavy lifting is already behind us on this project though, so no need to over complicate the last step. After creating a new actor named “Score Display”, we’ll add in a Display Text behavior. Open up the Expression Editor by clicking “e” icon on the right side of input field, and select the Total Score game attribute.
Before throwing the Score Display actor into the scene, let’s take a quick moment to tailor the presentation of the score. We’ll set the Alpha Color of the “Score Display” actor to 0 so the background of the actor doesn’t show up – just the score itself. Drag an instance of the Score Display actor into the scene and presto — you’re done!