Limit loop iterations and break early when possible:
loop all players: if loop-player has permission "admin": send "Alert: Server restarting" to loop-player if loop-player is op: send "You can delay with /delay" to loop-player stop loop # Found the op, no need to continue
Use stop loop to exit a loop early once you’ve found what you need.
command /setup: trigger: set {_loc} to player's location set block at {_loc} to chest set {_inv} to inventory of block at {_loc} add diamond, emerald, and gold ingot to {_inv}
set {homes::%uuid of player%::%arg-1%} to player's locationset {lastLogin::%uuid of player%} to nowset {kills::%uuid of attacker%::total} to {kills::%uuid of attacker%::total} + 1
Use meaningful names that explain the variable’s purpose at a glance.
# Home system - allows players to set and teleport to saved locations# Stores homes in {homes::<uuid>::<name>} formatcommand /home <text> [<text>]: description: Set, delete or travel to your home. trigger: # Handle "set" subcommand if arg-1 is "set": if arg-2 is set: # Save location with player's UUID for name-change safety set {homes::%uuid of player%::%arg-2%} to player's location send "Set your home <green>%arg-2%<reset>" to player
# Player stats structure{stats::%uuid%::kills}{stats::%uuid%::deaths}{stats::%uuid%::playtime}# Home locations structure {homes::%uuid%::<home-name>}{homes::%uuid%::home1}{homes::%uuid%::home2}# Guild data structure{guild::%guild-name%::leader}{guild::%guild-name%::members::*}{guild::%guild-name%::balance}
on quit: # Delete temporary session data delete {temp::%uuid of player%::*}command /home remove <text>: trigger: if {homes::%uuid of player%::%arg-1%} is set: delete {homes::%uuid of player%::%arg-1%} send "Home deleted" to player
Local variables ({_var}) are automatically cleaned up. Only manually delete global variables.
command /teleport <player>: trigger: if arg-1 is online: teleport player to arg-1 send "Teleported to %arg-1%" else: send "<red>Player %arg-1% is not online"
command /home set <text>: trigger: if length of arg-1 > 16: send "<red>Home name must be 16 characters or less" stop set {homes::%uuid of player%::%arg-1%} to player's location send "<green>Home '%arg-1%' set successfully"
command /pay <offline player> <number>: trigger: # Check: not paying yourself if arg-1 is player: send "<red>You can't pay yourself!" stop # Check: positive amount if arg-2 <= 0: send "<red>Amount must be positive" stop # Check: sufficient balance if {balance::%uuid of player%} < arg-2: send "<red>Insufficient funds" stop # Process payment remove arg-2 from {balance::%uuid of player%} add arg-2 to {balance::%uuid of arg-1%} send "<green>Paid %arg-2% to %arg-1%"
command /item <items>: permission: server.item permission message: <red>You don't have permission to use this command trigger: # Additional check for dangerous items if player doesn't have permission "server.item.all": loop argument: if loop-item is tnt or bedrock: send "<red>You can't spawn %loop-item%" else: give loop-item to player else: give argument to player
command /pay <offline player> <number>: permission: server.pay trigger: # Prevent: paying yourself to duplicate money if arg-1 is player: send "<red>You can't pay yourself" stop # Prevent: negative payments to steal money if arg-2 <= 0: send "<red>Amount must be positive" stop # Prevent: paying more than you have if {balance::%uuid of player%} < arg-2: send "<red>Insufficient funds" stop
command /sethome <text>: trigger: # Validate: no special characters that could break variables if arg-1 contains "::" or "%%": send "<red>Invalid home name" stop # Validate: reasonable length if length of arg-1 > 16: send "<red>Name too long (max 16 characters)" stop set {homes::%uuid of player%::%arg-1%} to player's location
# Bad - continues after errorif player doesn't have permission "admin": send "<red>No permission"# Code continues executing!# Good - stops after errorif player doesn't have permission "admin": send "<red>No permission" stop # Prevents further execution
Not Checking if Variables Exist
# Bad - crashes if variable doesn't existadd 1 to {score::%uuid of player%}# Good - initializes if neededif {score::%uuid of player%} is not set: set {score::%uuid of player%} to 0add 1 to {score::%uuid of player%}# Better - use default valueadd 1 to {score::%uuid of player%}set {score::%uuid of player%} to {score::%uuid of player%} ? 0
Inefficient Loops
# Bad - loops all players every timeon damage: loop all players: if loop-player is victim: send "You took damage!" to loop-player# Good - direct referenceon damage: if victim is a player: send "You took damage!" to victim
Hardcoded Values
# Bad - hardcodedcommand /reward: trigger: give player 5 diamonds wait 3600 seconds# Good - configurableoptions: reward_amount: 5 reward_cooldown: 1 hourcommand /reward: trigger: give player {@reward_amount} diamonds wait {@reward_cooldown}