# Set Object Actions

## Begin Game Maker 4

### Customize Object Behaviours & Tags

#### :yellow\_circle: MEDIUM

In this activity, you will learn how to create custom interactions between objects using simple AI-driven behaviors and their tags, or identifiers. Behaviors that use AI decision making are programmed to detect and respond in certain ways depending on your modifications.

{% embed url="<https://youtu.be/sAlcyMGRKlw?feature=shared>" %}

{% tabs %}
{% tab title="About" %}

### **Launch Game Maker**

* Open or create an Experience.
  {% endtab %}

{% tab title="Built-In Logic" %}

### **Default Settings**

**Prey & Predator**

* Place a "**Stag"** asset and apply **Prey** behavior. This includes the *Prey* tag.
* Place a "**Grey Wolf**" asset nearby and apply **Predator** behavior. *Predator* tag is included.
* **Press** **`TAB`** to **Test:**&#x20;
  * The **Predator** will detect the **Prey** and chase it.&#x20;
  * The **Prey** will run when it detects the **Predator** up closer.&#x20;
  * The **Predator** will chase any *Avatar*, or player, which is one of its default **Tags to Attack**.

### Custom Targets

**Plant & Prey**

* Select the **Prey** and notice that it has a **Food Tag** and **Tags to Flee**. Let's add objects with the *Plant* tag for it to detect.
* Place a "**Small Plant B**" asset nearby and duplicate it. For one of them, apply the **Plant** component. Scroll to the bottom of the object's Properties, type the tag *Plant* (case sensitive), and press enter to apply it.
* One plant has an identity so it can be "eaten" and the other is just a prop that won't be touched. Duplicate (**`CTRL`+`D`**) both types and spread them in a small area.
* **Press** **`TAB`** to **Test:**&#x20;
  * Watch the **Prey** wander, approach objects it should eat, and make them disappear while ignoring the rest.

{% hint style="info" %}
**THINK OUTSIDE THE BOX**

These behaviors are meant to be a ***function*** with flexible use.

* Make an NPC collect trash using the **Prey** or **Farmer** behaviors by adding any custom tag as their food or gathering target.
* Only add the custom tag to objects you want **Farmer** or **Prey** to remove.
  {% endhint %}
  {% endtab %}

{% tab title="Changes During Play" %}

### **Changing Tags During Play**

**Soldier & Citizen**

* Place an "**Axeman Recruit**" and apply **Soldier** behavior. Its default **Tags to Attack** includes *Hostile*.
* Place an "**Elder Caveman**" with **Citizen** behaviour.
* **Press** **`TAB`** to **Test:**
  * You can't attack the **Citizen** because it has the built in tag *Friendly*.
  * The **Soldier** will ignore you until you attack, which will apply the tag *Hostile* to your Avatar for the rest of the game!
  * If you exit Play mode and re-enter it later, the game is reset, so the *Hostile* tag will be cleared from your Avatar.
    {% endtab %}

{% tab title="Battle!" %}

### **Custom AI Interactions**

**Melee Enemy vs. Melee Enemy**

***GroupA***

* Place three "**Maximilien**" objects together. Select all of them and apply these changes in the Properties panel (which will change them all at the same time):
  * Apply **Melee Enemy** behaviour
  * Next to **Tags to Attack**, click the **X** to remove the *Hostile* tag, click **`ADD+`**, and type *GroupB* in the text box.
  * Scroll to the bottom of the Properties panel and apply the tag *GroupA* (remember to press **`ENTER`**)

***GroupB***

* Place three "**Matthew**" objects together. Select all of them and apply these changes in the Properties panel:
  * Apply **Melee Enemy** behaviour
  * Next to **Tags to Attack**, click the **X** to remove the *Hostile* tag, click **`ADD+`**, and type *GroupA* in the text box.
  * Scroll to the bottom of the Properties panel and apply the tag *GroupB* (remember to press **`ENTER`**)

**Press** **`TAB`** to **Test:**

* *GroupA* and *GroupB* will detect each other's tags and fight. Feel free to select these groups, duplicate them a few times, and create a small army of dueling NPCs! :crossed\_swords:
  {% endtab %}
  {% endtabs %}

### Follow Up

Combine a variety of AI-driven behaviors and use tags to direct their decision making. Explore these ideas and your own:

* Want players to join a side in a battle? Add *Avatar* to any enemy's **Tags to Attack**.
* Want fighters to be revived during battle? Use the **Healer** behavior with **Tags to Heal**.

There are many other behaviors to explore, but you've learned the basics of controlling object actions by applying behaviors and custom tags.

In the next activity, you'll create functional game logic with other behaviours and add components to make objects more interactive.

***

## :heavy\_plus\_sign: Relevant Resource

<table data-view="cards"><thead><tr><th data-type="content-ref"></th><th></th><th data-hidden data-card-cover data-type="files"></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><a href="../docs/using-assets-and-objects/tags">tags</a></td><td>Set an object's identity tags to customize actions and interactions. This is an important part of using logic in Game Maker, which starts with the next activity.</td><td><a href="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FT0875ivHSmvrt7Kb8Blq%2Fimage.png?alt=media&#x26;token=e58a31a8-2210-4df0-a1b9-6705176f0cf1">gm tags.png</a></td><td></td></tr><tr><td><a href="../docs/behaviours">behaviours</a></td><td>There are many more behaviours than what is included in this activity. See this page for a summary and general uses for all behaviours.</td><td><a href="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FIxYGg3L3AfkFjli5hX2y%2Fbehaviors%20transparent%20crop.png?alt=media&#x26;token=6ed56077-5da6-4955-a018-17d380eac66d">behaviors transparent crop.png</a></td><td></td></tr><tr><td><a href="../docs/using-assets-and-objects/behaviour-and-component-parameters">behaviour-and-component-parameters</a></td><td>Learn about different parameter types built into behaviours and components so it's easier to customize logic.</td><td><a href="https://content.gitbook.com/content/83PS3g9zpWmq73xzlwFn/blobs/ekamG2hLp4XHYmcMhqoL/image.png">gm edit logic parameters.png</a></td><td></td></tr><tr><td><a href="../docs/build-menus/properties-panel">properties-panel</a></td><td>Learn to use the Properties panel to view permanent and customizable aspects of a selected object or group of objects.</td><td><a href="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FZmaBHfzyChYI8OtbpyQu%2Fgm%20properties%20panel.png?alt=media&#x26;token=1e69bae9-a020-4ba8-9202-2fdc1c812b24">gm properties panel.png</a></td><td></td></tr><tr><td><a href="../creative-guides/experience-design-techniques/narrative-design/storyboard">storyboard</a></td><td>Organize your game flow with some simple sketches. We recommend some useful tools.</td><td><a href="https://331512196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F83PS3g9zpWmq73xzlwFn%2Fuploads%2FlQtvKt6ItWh8lr8ggD0k%2FEAbond-bw04.jpg?alt=media&#x26;token=26f87a95-61f1-4483-8c67-495e419a75ea">EAbond-bw04.jpg</a></td><td></td></tr></tbody></table>

***

## Forum: Community Ideas & Support

<table data-card-size="large" data-view="cards"><thead><tr><th></th><th data-hidden data-card-cover data-type="files"></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td><a href="https://forum.sandbox.game/t/begin-game-maker-series-4-set-object-actions/1815"><strong>Visit the Forum</strong></a></td><td><a href="https://content.gitbook.com/content/83PS3g9zpWmq73xzlwFn/blobs/R2GdZMImITUqYrmiThBY/13%20community%20%20-%20%20blog.png">13 community  -  blog.png</a></td><td><a href="https://forum.sandbox.game/t/begin-game-maker-series-4-set-object-actions/1815">https://forum.sandbox.game/t/begin-game-maker-series-4-set-object-actions/1815</a></td></tr><tr><td><p>A forum post has been created for this learning activity! Visit to:</p><ul><li>Ask or answer questions</li><li>Post ideas about the topic</li><li><p>Share what you've learned or created</p><ul><li>from the activity</li><li>from the bonus resources</li></ul></li></ul></td><td></td><td><a href="https://forum.sandbox.game/t/begin-game-maker-series-4-set-object-actions/1815">https://forum.sandbox.game/t/begin-game-maker-series-4-set-object-actions/1815</a></td></tr></tbody></table>

***

## Other "Begin Game Maker" Videos

<table data-header-hidden><thead><tr><th data-type="content-ref"></th></tr></thead><tbody><tr><td><a href="play-test">play-test</a></td></tr><tr><td><a href="build-with-blocks">build-with-blocks</a></td></tr><tr><td><a href="place-assets">place-assets</a></td></tr><tr><td><a href="set-object-actions">set-object-actions</a></td></tr><tr><td><a href="trigger-logic">trigger-logic</a></td></tr><tr><td><a href="craft-quests">craft-quests</a></td></tr><tr><td><a href="set-up-mechanics">set-up-mechanics</a></td></tr><tr><td><a href="build-multiplayer-games">build-multiplayer-games</a></td></tr></tbody></table>
