Set Up Mechanics
This activity is included in an 8-part, 1 hour series to learn Game Maker. Short, focused topics with guided practice will give you practical experience building useful logic for creating games.
Begin Game Maker 7
Add Game Mechanics with Rules
🔴 COMPLEX
In this activity, you will learn the basics of the Game Rules system and how to apply it for more engaging game mechanics that can be used repeatedly. This visual scripting system is an efficient tool for designing behind the scenes logic using variables, unlocking many new gameplay varieties and a customizable HUD, or heads up display, for the player.
STAY ORGANISED IN GAME MAKER
Group rules into rulesets any way you like.
Group objects in the hierarchy using folders.
Find messages sent and received with the Message Inspector in the Debug menu.
Manage messages used in your Experience in the Settings menu.
What are Rules?
The Game Rules system is a visual scripting tool located in the Gameplay menu.
It allows you to set, use, and change values such as numbers, text, time, and true/false values for your gameplay needs and control what appears on the player HUD, or heads up display.
Launch Game Maker
Open the Experience from the previous activity to reuse some of its logic.
Trigger: Joining the Game
Let's begin with a simple popup window that appears when a player enters the game:
Rule: Popup Window Type: Game Screen
Required Message: Playerjoined
Title: Welcome!
Description: Explore as a player to test the logic you create.
Rule: OnPlayerJoin Type: Events
Message to Send: Playerjoined
Test
Press TAB to test. The popup window appears as soon as the Experience starts for you.
For now, let's set the Popup Window rule's Required Message to none so the window won't pop up every time we press TAB to enter the game and test logic.
Use a Text Variable in a Rule
Create a variable and a rule to use it:
Variable Type: Text
Apply variable: Global Name: Area Value: Banner Text
Rule: Banner Type: Game screen
Required Message:
NightDuration: Fixed value of 5 (seconds)
Variable: Area
Name: Area
Icon: Map
Test
In a previous activity, the message Night is sent anytime the player enters an object's trigger volume. The banner will display the words "Banner Text," which is the value saved in the variable.
Overwrite a Text Variable and Reuse It
Let's create a message with arguments to send different text to the Rules System depending on where the player is located in the game world.
Logic Asset
Trigger Volume component
Enter Message:
Message (with argument):
AreaArgument 1: Text
Argument name: Area Name
Argument value: Area 1
Broadcast type: Rules
Logic Asset
Trigger Volume component
Enter Message:
Message (with argument):
AreaArgument value: Area 2
Broadcast type: Rules
Now create a rule to overwrite the variable's text with the message argument:
Rule: Set Text Value Type: Replace Variable Values
Required Message: Area
Text variable: Area
New text: Message Argument, select argument name you created
Test
The banner rule doesn't use the text argument sent with the message, but still works. The rule to sets banner text uses the argument text included with the message.
Trigger: Keypress (to shoot projectiles)
Create a preset of the following asset. Delete the object after saving it as a preset.
[MP] Asset: Numpad Switch Invisible
Projectile behaviour
Start with Experience: True
Message Required: none
Projectile Force: 40
Projectile Trajectory: 0
Look at Direction: True
Collision Target: SpecificTags
Tags to Collide With: artifact
Message on Collision:
HealthHealth: - 100
Broadcast Type: CollidedActors
Note: With these settings, the projectile will cause 100 damage if it hits an object that has the tag artifact, which was applied to objects in the previous activity.
Now create a pickable object with a child object that spawns the projectile preset:
[MP] Asset: Dragon Egg
Visual FX Component
Beverage wisp
Pickable component
Offset: x
0y-0.5z0Note: This offset adjusts the object location when it is picked up.
[MP] Asset: Numpad Switch
Location: Inside the dragon egg asset Child object of the dragon egg Invisible
Asset Spawner behaviour
Message Required:
1Use Preset: True
Preset: Select your projectile preset
Only once: False
Add a Key Input rule to trigger the projectile to spawn whenever a key is pressed:
Rule: Key Input Type: Triggers
Select Key: 1
Message to send onKeyDown: 1
Test
Press TAB to test. Pressing the 1 key shoots the projectile from the dragon egg anytime. Pick up your magical dragon egg with E and shoot all ancient artifact assets to collect the treasure!
Since an object that is picked up can’t send or receive messages in the current version of Game Maker, we created a child object to be the asset spawner. The projectile behavior triggers as soon as the object it’s applied to is spawned.
Count Resources with a Number Variable
Place the treasure preset from the last activity. Modify its collectable component so it will send a message to the Game Rules system whenever it is collected. Save this preset over the old version. Delete the object after saving it as a preset.
Asset: Ancient Treasure A Tag: treasure
Indicator component
Linked Quest ID: Treasure Hunt
Quest cursors: True
Objective: Treasure Hunter
Collectable component
Collect Sound: Generic Coin
Message on Collect:
Treasure.CollectBroadcast Type: All
Note: Each time this object is collected, the message is sent to all systems.
Modify all of the Ancient Artifact assets to drop the preset when destroyed:
Modify Assets: Ancient Artifact Tag: artifact
Health component
Health: 10
Drop component
Use Preset: True
Preset: Select your treasure preset
Duplicate an Ancient Artifact asset until there are at least 20 in the game. Spread them out.
Create the following variable and rules to track and display money:
Variable Type: Number
Apply variable: Local Name: Money Value: 0
Rule: Math Type: Math
Required Message:
Treasure.CollectOperand 1: variable, Money
Operator: Add
Operand 2: Fixed value, 100
Result: Money
Note: This amount replaces the variable.
Rule: HUD Type: Game Screen
Required Message:
PlayerjoinedSelect slot: Top center slot
Variable: Money
Name: Treasure
Choose icon and size
Note: This displays the variable on the HUD from when a player enters the game.
Test
Press TAB to test. Now as you destroy the ancient artifacts and collect the treasure that drops, you'll see the amount of treasure collected (100 per treasure). Each time you collect the treasure, which is a preset, you’re sending a message to a custom location.
In this case, it goes to All locations so it will reach the Rules system and increase your money when collected, which appears in the HUD slot you selected.
Make Variables Useful
Create an NPC to sell different types of items to players (equipment to wear, a consumable item, and a resource to be shown in the player HUD):
Asset: Bazaar Merchant
Asker behaviour
Question: "What would you like to buy today?"
A1: "Food" A1 message:
ShopItem1A2: "Equipment" A2 message:
ShopItem2A3: "Wood" A3 message:
ShopItem3
Create a preset object to spawn when purchased (delete after saving as a preset):
Asset: Any food item
Collectable component
Consumable: true Note: Press
Cin Inventory to useMessage on consume:
Speed, Percentage 20, Duration 10 Note: This gives a 10 second boost
Create asset spawners for items to purchase and collect:
Logic Asset
Asset Spawner behaviour
Message required:
ShopItem1PurchasedAsset to spawn: any equipment asset
Component: Collectable
Logic Asset
Asset Spawner behaviour
Message required:
ShopItem2PurchasedSpawn preset (toggle): true
Preset: the food preset you created
Add variables and rules for resources that will be tracked by number and displayed in the HUD:
Variable Type: Number
Apply variable: Local Name: Wood Value: 0
Rule: Math Type: Math Name: +Wood
Required Message: ShopItem3Purchased
Operand 1: Wood variable
Operator: Add
Operand 2: Fixed value, 5
Result: Wood variable
Note: This adds 5 to the wood variable
Rule: HUD Type: Game Screen
Required Message: Playerjoined
HUD slot: any bottom slot
Add a Shop rule preset to save time on the rest of the setup:

You already set up the Add Money, HUD, and Player Join rules earlier in this activity. You can remove the ones in this premade ruleset.
The remaining rules allow you to test if you have enough money to buy two types of items and pay from your money variable if you do have enough.
You have three items in your shop, so select and duplicate a Success, Fail, and Pay rule in this Ruleset to add what's needed for your third item.
Rename Item 1 rules "Purchase Food Success," "Purchase Food Fail," and "Pay Food." Rename Item 2 rules for equipment and item 3 rules for Wood to make it easier to track what each rule does in your custom setup.
Set the price of each item in the Success and Fail rules so it will check if you have enough and send a message if you don't, and use the same value in the "operand 2" value of the Pay rules to match and subtract an item's cost from your Money. Based on the number of treasures your game has, set food to cost 1, equipment to cost 4, and wood to cost 2, for example.
The messages sent by each rule matches the rest of the logic in the activity, but you can use custom messages to keep track of things more easily.
Finally, add a text variable and rule to inform players when they don't have enough money:
Variable Type: Text
Apply variable: Local Name: Purchase Status Value: You don't have enough money
Rule: Banner Type: Game Screen
Required Message:
ShopPurchaseFailedDuration: Fixed value of 5 (seconds)
Variable: Purchase Status
Name: Purchase Status
Test
If you destroyed some artifacts and collected treasure, you have money to spend with the merchant. You can set custom costs for each item in the Rules System and spawn any type of item you like or add resources for gameplay using variables.
Try opening your inventory to wear the equipment you purchased or consuming the food item that triggers a speed Power Up. The purpose of the items you buy are completely up to you.
Follow Up
The Game Rules System is a powerful visual scripting tool running behind the scenes to manage information and gameplay.
Other rule presets make it easy to track points, add time trials, set poison or hunger for players, and more. It's also possible to build a complex resource management system where messages with arguments trigger amounts of resources to be traded or purchased.
With rules, you can even define what variables are for all players and which ones will be tracked differently for each player. We'll explore that in the next activity about multiplayer games.
➕ Relevant Resources

Find details on each rule (or right click a rule in Game Maker for this info)
Forum: Community Ideas & Support
Other "Begin Game Maker" Videos
Last updated
Was this helpful?






