Scripting in Age of Empires IV involves being familiar with two main concepts: LUA and SCAR.
Understanding how these systems work in relation to the game is essential to beginning to make scripts for Age of Empires IV.
What is LUA?
LUA is a lightweight programming language designed to be embedded in other applications. This language has seen frequent use in game development across the industry for its flexibility, execution speed, and ease-of-use for integrating it into game engines.
If you already know how programming languages work, there are a few main things you might find different with LUA:
- LUA is Dynamically Typed, meaning that variables can be reassigned to different types on the fly. The function
scartype()returns the type of a variable.
- There are 8 basic types in LUA, but Age of Empires IV only uses 6 of these. They are: nil, boolean, number, string, function, and table.
If you are unfamiliar with programming languages and would like to create your own Crafted Map scenarios, Generated Maps, or Game Modes for Age of Empires IV, it is recommend you start by learning LUA.
There are multiple resources online to begin your journey, including on the official LUA website.
What is SCAR?
SCAR (short for “Scripting At Relic”) is a programming language based on LUA that can run during a match in Age of Empires IV.
SCAR is the result of integrating LUA into the Age of Empires IV Content Editor, combined with a number custom functions that allow for easy modification of game objects and parameters.
This means if you are familiar with how to script in LUA, you also know how to script in Age of Empires IV.
By using your LUA knowledge to explore Age of Empires IV's built-in SCAR functions, you should be able to spawn and command units, set objectives, destroy buildings, and a variety of other core functions.
Age of Empires IV employs SCAR in a variety of uses, including creating:
- Multiplayer game mode logic
- Campaign missions
- Procedural map generation
- Debug functions
SCAR is useful in these situations because of how it works, as it runs at a “global” level.
With SCAR, there is only a single script running which can be doing multiple things, allowing it to preside over the entire game session. This makes SCAR perfect for using in content such as scripted missions or custom game modes.
Scardocs is a file bundled with the Age of Empires IV Content Editor that contains a large list of useful functions.
You can access Scardocs through the Main Menu and navigating to Script > Documentation. This will open up Scardocs in your web browser.
To use Scardocs, perform the following steps:
- Select a category of functions in the left panel.
In the example below, we selected FOW. This category contains functions that allow you to control the Fog of War in a match.
- Select a function in the category to view its description and parameters.
In the example below, FOW_RevealAll is selected. Note that this function reveals the Fog of War for all players when it is called. It does not have any parameters which makes it easy to use. If you wish to reveal a specific area, you would call FOW_RevealArea, but you would first need to identify a position on the map, set a radius/duration, and feed that information into the function when you call it.
- Use the function in your Crafted Map or Game Modes script.
You can learn more about scripting functions in the Creating a Script documentation for either Crafted Maps or Game Modes.