Variables & Substitution
Learn how to use variables to make your aliases dynamic and powerful.
What are Variables?
Variables are placeholders that get replaced with actual values when commands run.
Example:
/addcommand add hello say Hello ${player}!
When you run /hello, ${player} gets replaced with your username.
Built-in Variables
These variables are always available:
| Variable | Description | Example | Notes |
|---|---|---|---|
${player} |
Your username | Steve | Always available |
${x} |
Your X coordinate | 123 | Precise location |
${y} |
Your Y coordinate | 65 | Elevation |
${z} |
Your Z coordinate | -450 | Precise location |
${syntax_name_param} |
Custom syntax parameter | ${tpa_player} | From patterns |
${custom_var} |
User-defined variable | ${server_ip} | Create with /setcmdvariable |
Using Variables
Player Variable
/addcommand add whoami say You are: ${player}
/addcommand add greet say Hello, ${player}! Welcome back!
Coordinate Variables
/addcommand add here say ${player} is at X:${x} Y:${y} Z:${z}
/addcommand add coords say Coordinates: ${x}, ${y}, ${z}
Combined
/addcommand add location say ${player} is at (${x}, ${y}, ${z})
Custom Variables
Create your own variables that don't change frequently:
Creating a Custom Variable
/setcmdvariable server_name "MyAwesomeServer"
/setcmdvariable admin_discord "https://discord.gg/example"
/setcmdvariable spawn_coords "0 65 0"
Using Custom Variables
/addcommand add discord say Join our Discord: ${admin_discord}
/addcommand add about say Server: ${server_name}
/addcommand add spawn tp ${player} ${spawn_coords}
Custom Syntax Variables
Parameters from syntax patterns become variables:
Pattern Definition
{
"tpa": {
"pattern": "/tpa <player>",
"description": "Teleport request"
}
}
Creating the Variable
The syntax name is tpa and parameter is player:
${tpa_player}
Using in Alias
{
"tpa": "tellraw ${tpa_player} {\"text\":\"${player} requests TPA\",\"color\":\"yellow\"}"
}
Multi-Parameter Variables
Pattern with Multiple Parameters
{
"ban": {
"pattern": "/ban <player> <reason>",
"description": "Ban a player"
}
}
Variables Created
${ban_player}- The player name${ban_reason}- The ban reason
Using Both
{
"ban": "ban-ip ${ban_player} && say [BAN] ${ban_player} banned for: ${ban_reason}"
}
Three Parameter Example
{
"msg": {
"pattern": "/msg <player> <color> <message>",
"description": "Send colored message"
}
}
{
"msg": {
"pattern": "/msg <player> <color> <message>",
"description": "Send colored message"
}
}Variables:
${msg_player}${msg_color}${msg_message}
{
"msg": "tellraw ${msg_player} {\"text\":\"${msg_message}\",\"color\":\"${msg_color}\"}"
}
Variable Naming Rules
- Variables are case-sensitive
${Player}and${player}are different- Use lowercase for consistency
- Custom variables must not contain spaces
- Use underscores instead:
${my_variable} - Names can contain letters, numbers, underscores
Advanced: Combining Variables
Multiple Variables in One Command
/addcommand add info say ${player} is at ${x} ${y} ${z} on ${server_name}
Variables with Text
/addcommand add status say Status: ${player} - OK (${server_name})
Variables in Selectors
/addcommand add heal effect give @s instant_health 1 && say Healed ${player}
Variable Examples
Welcome System
/setcmdvariable server_name "Adventure Server"
/setcmdvariable rules_url "https://rules.example.com"
/addcommand add welcome say Welcome to ${server_name}, ${player}!
/addcommand add rules say Read our rules: ${rules_url}
Teleport System
/setcmdvariable spawn_point "0 65 0"
/setcmdvariable pvp_arena "1000 100 1000"
/addcommand add spawn tp ${player} ${spawn_point}
/addcommand add arena tp ${player} ${pvp_arena}
Moderation System
/setcmdvariable kick_reason "Breaking server rules"
/setcmdvariable ban_reason "Permanent ban for serious violations"
/addcommand add kick kick ${player} ${kick_reason}
/addcommand add ban ban ${player} ${ban_reason}
Viewing Custom Variables
Custom variables are stored in:
.minecraft/config/CommandMaker/variables.json
You can edit this file directly or use commands:
/setcmdvariable name "value" # Create or update
/setcmdvariable name delete # Delete (for future versions)
Variable Performance
- Built-in variables (
${player},${x}, etc.) have minimal impact - Custom variables are loaded once at startup
- No performance penalty for using variables
- Substitution happens instantly
💡 Pro Tip
Use meaningful variable names like ${server_ip} instead of ${a} for readability!
Troubleshooting Variables
Variable not replacing?
- Check spelling (case-sensitive!)
- Use correct syntax:
${variable} - Make sure variable exists if custom
- Reload with
/addcommand reload
Getting literal ${} in chat?
WRONG: /addcommand add test say $player
RIGHT: /addcommand add test say ${player}
Custom variable returns nothing?
1. Create it first: /setcmdvariable myvar "value"
2. Use in command: /addcommand add test say ${myvar}
3. Reload: /addcommand reload