# Collect Points

## ![](https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FVPbZ1ggAARWvUypYIrgP%2Fimage.png?alt=media\&token=c782fbc0-86ba-4a23-a21c-172e2b3ed033) Game Rules Preset Available

The **Collect Points** Preset can be used to track scores like enemies defeated or coins collected. Once a certain amount is reached a completion message is sent out.

{% hint style="warning" %}
**APPLYING PRESETS TO YOUR EXPERIENCE LOGIC**

Presets will only add rules, variables and messages in and out. To create a fully working game mechanic you also need to add assets with behaviours and components to communicate with the Preset.

See an example of applying a Ruleset for a **Collect Points** mechanic below.
{% endhint %}

### Add a Preset

1. Click Gameplay in the Top Bar and select the Game Rules tab.
2. Click Presets in the Island Menu on the left.
3. Click on a Preset to add it to your grid board.

Visit the [**Game Rules**](https://docs.sandbox.game/en/creator/game-maker/docs/game-rules) page for full documentation, including controls for easy use.

### Rules Included

<div data-full-width="true"><figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FPrWogMXTKZ9nG19RCcls%2Fimage.png?alt=media&#x26;token=e293ce32-fe75-4a9c-aea8-4f2a59665be9" alt=""><figcaption><p>Game Rules Preset - Collect Points (click to enlarge)</p></figcaption></figure></div>

### Rules Logic

{% tabs %}
{% tab title="Info" %}
In this example, every Rule is explained in detail.

You can also right click a Rule on the grid board to view more detailed information about each **Logic Box**.

<div align="left"><figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FFh11itlSaHdlzIUgbylV%2Fimage.png?alt=media&#x26;token=be286e48-4fc2-4957-a907-f57e4e4fe833" alt=""><figcaption></figcaption></figure></div>
{% endtab %}

{% tab title="Points Counter" %}

### **Points Counter (Add/Subtract number)**

The first rule in the **Collect Points** preset is a **Add/Subtract number** rule called Points Counter. This is also the most essential rule, since it is used to modify the Score variable upon receiving a message. It is initially set up to receive the message called Score as its activating Message. This message and a few others are initially created within the experience and can handily be used for the gameplay rules. It is also a message containing a number argument, so it is possible to send more information within this message.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2F2fDqv8Lpr2DBZTYS8KXJ%2Fimage.png?alt=media&#x26;token=10082d1a-9bb1-4f80-b926-6120efd863fc" alt=""><figcaption></figcaption></figure>

#### **Target variable**

The target variable that this rule will change can be changed, but since it is already set to the global Parameter “Score” which was created automatically, it is not necessary to change this field.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FSN3ivxLiJktnfMIwF3Z9%2Fimage.png?alt=media&#x26;token=60c2f5ea-3e10-4fd5-ab15-cd0dde4d1be8" alt=""><figcaption></figcaption></figure>

#### **Using Message Arguments**

To ensure, that this the message arguments work as intended the Value change must be set to Message Argument and then make sure that the argument is set correctly to Points. This means that whenever the Score message is send, its argument will be added to the Score Variable of the gameplay rules.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FSO2FrgwzGzKkskNsqwQE%2Fimage.png?alt=media&#x26;token=698f85ae-0056-4d4d-a8fa-28e4af520902" alt=""><figcaption></figcaption></figure>

#### **Message to send when a value is changed**

For the next steps it might be helpful to have something react every time the score is modified. This could be a check if the games goal is met or visual effects or sounds that are triggered within the experience. To do this we use the Message to send field. This will already have the message **ScoreChanged** set up, which will send whenever the Score variable has been modified.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2Fty2WS7isilLAk9vJ5bMQ%2Fimage.png?alt=media&#x26;token=e359484b-14d3-435c-803c-ee7537f19c66" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Trigger Message on Amount" %}

### Trigger Message on **Amount (Compare numbers)**

The Send Message On Amount rule is used to compare the current value of the Score variable to another value. This can be useful to define goals like “collect 10 points”. Once this check is true it will send out a message to the experience.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FAvCdZLBuCwjIZ8Wq7pVt%2Fimage.png?alt=media&#x26;token=21f52312-c874-494a-a96b-eeec621ef93d" alt=""><figcaption></figcaption></figure>

#### Required **Message**

Again this message activates the rule and allows for the check to happen. Since we have defined a message when the score is modified in the Add/Subtract number rule, we can reuse that here. This way, every time the score is changed it will also be checked for a reached condition.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FBwzXiNRq36oS3uPzQD9h%2Fimage.png?alt=media&#x26;token=28f9b3ed-39da-430c-b917-284f7e12f057" alt=""><figcaption></figcaption></figure>

#### **Number Variable**

This field is automatically set to the Score variable, so we do not have to change anything here.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FY6FjUVd55eStZNOUph26%2Fimage.png?alt=media&#x26;token=d87bf436-8615-48d8-bfa0-8963a9f93939" alt=""><figcaption></figcaption></figure>

#### **Condition**

There are multiple ways to compare the two values. In this case we want to check if a score has reached ten. Since we want to define varying scores for objectives it would be smart to set the comparison to *Greater Equals* instead of *Equals*. In most cases *Equals* might be sufficient as a default value. Keep in mind that the Number variable is always the first value in this comparison, so *Greater* means that the number variable (Score) is greater than the fix value (10) in this case.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FvF3ajraYv6aygSJpK5Qg%2Fimage.png?alt=media&#x26;token=52566518-903d-4e7d-a0ea-10da2fac9eb2" alt=""><figcaption></figcaption></figure>

#### **Compare Value Source**

In this example we want to check if the score has reached 10, so we can leave the comparison source at *Fix Value*. It would also be possible to compare to another variable or to a message argument, but that is not necessary in this case.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2Fy4lqYEB0Cp7xivsSEO3Z%2Fimage.png?alt=media&#x26;token=43c847b3-5344-40f9-ac02-a779ce8754cc" alt=""><figcaption></figcaption></figure>

#### Comparison duration

The comparison duration allow us to create an event in the background, that will trigger when a condition is met. This check mark allows us to set the rule to check for the conditon to be met continuously. As we are checking the Amount every time the value is modified though, this will not be necessary here and we can leave it on *Once*.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2F9TdqlzxN6kL7pfQstnGr%2Fimage.png?alt=media&#x26;token=c95acaf1-7b8d-4cfd-a59e-c58f5120212d" alt=""><figcaption></figcaption></figure>

#### Outgoing **Message**

Last thing to do in this tree is to define a message that will be sent, once the goal is met. In this case we have the predefined message *GoalReached.*

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2F8jxhdl1PBDFqN3aUnIHL%2Fimage.png?alt=media&#x26;token=794a25ba-f7a8-47a6-9127-37a4b598178f" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Set Value" %}

### **Set Value (Set number value)**

The set number value rule can be used to set the score to a specific number instead of adding a value. In this example it is not used but it could be used for a reset for instance. It is also possible to use variables or message arguments here, but we will leave the value at *Fix value* and *0* for now. The rest can also be left as is.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FOruCfaBdSCSZVYogFHku%2Fimage.png?alt=media&#x26;token=6ccf16a9-47f6-4136-9e70-11e006e851ac" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Show Info" %}

### Show Info (Set true/false value)

Since our example uses a score that the player wants to keep track of, we have the Set true/false value rule available to toggle the Show Rules HUD variable on and off using the ***ShowInfoDisplay*** message. By default the variable is set to true though so this would only be needed if the creator turns that off.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2F5pqZUW8hOQhG7K9jIv4W%2Fimage.png?alt=media&#x26;token=a5a412bc-a6c1-457b-8f4e-cf410f0f7771" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Display Score" %}

### Display the Score (Display variable on HUD)

Since we want to inform players about their current score also need to activate the Display Score rule which is done with the *DisplayScore* message.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FeDgCnPqbGqaS3YyqCOSF%2Fimage.png?alt=media&#x26;token=2e40b67b-b7eb-4695-815a-578f65227d68" alt=""><figcaption></figcaption></figure>

#### **Initially showing the value instead**

To display the value initially and not only once it is changed, we can go to the Score variable in the variable list end click and open up the settings for the Score variable.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2Fjvi1ybCFwTszHqNspvwp%2Fimage.png?alt=media&#x26;token=dfa4d0c6-9db4-4322-97a4-6e06c775a278" alt="" width="293"><figcaption></figcaption></figure>

This will open variables settings where we can change a variables internal and displayed name, its default value and if it is initially displayed.

To initially show it, we will check the “Shown at game start” checkbox in the Heads-Up Display Settings.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FschNZ5XhV92JeUylrT4O%2Fimage.png?alt=media&#x26;token=716f54a7-e4bf-4af2-914c-b7e77ec93bdf" alt="" width="315"><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

### Object Logic

{% tabs %}
{% tab title="Info" %}
In this example we will create a simple collection game, where players collect a number of items with varying score values.
{% endtab %}

{% tab title="Collectables" %}

### **Collectables**

We add an asset to the experience and create a collectable Component. The Collect action required can be left at *Collision*. In the Edit Logic mode we will then set the Collect Message to *Score.* This is the message that the rule system needs to change the value of the score variable. Since the *Score* message contains an argument called *Score* a new field appears where we can set the amount of points this item will give. This will be set to 1.

The next important step is to change the Broadcast Type to Rules so the Component will only communicate with the Game Rules *.* The whole set up should look like this:

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2F5paZcMVesVJdgrDhaPJf%2Fimage.png?alt=media&#x26;token=04abe4b6-958f-48ac-9a44-0ccb0b856948" alt="" width="375"><figcaption></figcaption></figure>

We can than add other assets with the same component but other score values.
{% endtab %}

{% tab title="Winning Fireworks" %}

### **Winning Fireworks**

Since this is a minigame and should not end the whole experience we will reward the player with a nice firework instead. It is also possible to spawn rewards, open doors or to trigger the Victory screen.

We add a VFX asset and set the visual effect to *Fireworks.* Enabled at Start will be set to *False* and Message to TurnON to *GoalReached*. This way we make sure to not trigger the vfx too early.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2F6i3K1n5B86BF7n3uD3iK%2Fimage.png?alt=media&#x26;token=b71553a5-5d2e-44d2-a6c5-b1e901079c54" alt="" width="375"><figcaption></figcaption></figure>

If you play the experience now you’ll notice that the Firework is triggered once you collect 10 points, but you do not see any indicator in the UI. This is because we have not toggled the Display Score.
{% endtab %}

{% tab title="Toggle the Display Score" %}

### **Toggle the Display Score**

Currently, every message that is sent to the gameplay rules needs to have a Player as its starting point. This will work with collections, defeated enemies etc but it won’t work for Message Broadcasters that send a message right away. Instead we will use a trigger area that overlaps with the Avatar’s Portal, to make sure the player will trigger it. The Enter Message will be set to *DisplayScore* and set the Message’s argument to true. In addition we will set the Broadcast Type to Rules as the Game Rules are the only part of the experience, that require this message.

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FPpcovT2kRJ88VliNNkPU%2Fimage.png?alt=media&#x26;token=a3dbfcae-36e1-42f6-8a69-5082c2b751ed" alt="" width="375"><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

## Template Available

<figure><img src="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FHje2dukmy9Gy7xdLYXvn%2Fimage.png?alt=media&#x26;token=5fe3fb84-d464-4791-8d84-61863bf61a94" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sandbox.game/en/creator/game-maker/creative-guides/game-rules-guide/collect-points.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
