Master Garry's Mod Expression 2 (E2) basics. Learn Wiremod, E2 chips, inputs/outputs, and create simple logic like counters and automated systems.
Expression 2 (E2) is a powerful, Lua-based programming language within the Wiremod addon for Garry's Mod, designed for creating complex electronic devices and logic circuits. While it has a steep learning curve, understanding its basic principles allows you to build incredibly sophisticated contraptions, from automated systems to interactive machines, far beyond what standard props and tools can achieve.
What is Expression 2?
E2 allows you to write code that runs on a special entity called an 'Expression 2 Chip.' These chips can interact with the game world, read sensor data, control other entities, and perform complex calculations. It's the backbone of advanced automation and logic in Garry's Mod.
Getting Started with E2
- Install Wiremod: Ensure you have the Wiremod addon installed, usually via the Steam Workshop.
- Spawn an E2 Chip: In-game, open the Wiremod menu (often accessed via the 'Q' menu) and spawn an 'Expression 2' chip.
- Access the Editor: Aim at the E2 chip and press your use key (default 'E') to open the E2 editor.
- Basic Syntax: E2 uses a syntax similar to Lua but with specific keywords and functions for interacting with Garry's Mod entities and physics.
Fundamental E2 Concepts
- Variables: Store data (e.g.,
@MyNumber = 10). Variables starting with '@' are persistent. - Inputs and Outputs: E2 chips have defined inputs (to receive data) and outputs (to send data). You connect these to other Wiremod components.
- Functions: Predefined actions like
print()(to display text),owner():SteamID()(to get the owner's ID), orentity():SetPos()(to move an entity). - Events: Code that runs when a specific event occurs (e.g.,
runOnTick(1)to run code every frame,runOnChat("hello")to run code when someone says "hello").
A Simple Example: A Basic Counter
Let's create a simple E2 that counts how many times a button is pressed:
- Spawn an E2 chip and a button.
- Connect the button's 'Pressed' output to the E2 chip's 'Input' (you'll need to define an input in your E2 code).
- In the E2 editor, write:
@name Button Counter
@inputs Button
@persist Count
if (first()) {
Count = 0
}
if (Button) {
Count = Count + 1
print('Button pressed ' + Count + ' times!')
}
@name: The name of your program.@inputs Button: Defines an input named 'Button.'@persist Count: Makes the 'Count' variable save its value between sessions.first(): A special function that runs only once when the chip is spawned.if (Button): Checks if the 'Button' input is active (meaning the button was pressed).
Key E2 Functions for Beginners
print(message): Displays messages in the console.owner():SteamID(): Gets the SteamID of the chip's owner.entity():SetPos(vector): Sets the position of an entity.entity():GetPos(): Gets the position of an entity.timer(interval, callback): Creates a timer for recurring actions.
Learning Resources
- Wiremod Wiki: The official documentation for E2 functions and syntax.
- E2 Tutorials: Many community-made tutorials exist online.
- Experimentation: The best way to learn is by trying things out and seeing what works.
Expression 2 is a powerful tool that unlocks a new level of complexity and interactivity in Garry's Mod, allowing for truly unique creations.
100% Human-Written. AI Fact-Checked. Community Verified. Learn how AntMag verifies content