E2 (Expression 2) Programming Basics
Expression 2 (E2) is a powerful, custom scripting language integrated into Garry's Mod's Wiremod system, allowing for incredibly complex and custom logic. It's essentially a mini-programming language desed for creating advanced contraptions, AI, and unique game mechanics that go far beyond what standard Wiremod components can achieve alone.
An E2 chip is an entity that you can spawn using the Wiremod tool. Once spawned, you can open its editor (usually by right-clicking it with the Toolgun) and write Lua-like code. This code dictates the chip's behavior, allowing it to interact with the game world, read sensor data, control other entities, and perform calculations.
The core of E2 programming involves Inputs and Outputs, similar to standard Wiremod. Your E2 code defines how it processes incoming data from its Inputs and what data it sends out through its Outputs. You can also define variables to store information and use functions to organize your code.
Key concepts in E2 programming:
- Variables: Store data (numbers, strings, vectors, entities).
- Functions: Reusable blocks of code for specific tasks.
- Operators: Perform mathematical and logical operations (+, -, *, /, ==, !=, etc.).
- Control Flow: Use statements like `if/then/else` and `while` loops to control program execution.
- Built-in Functions: E2 provides a rich set of functions for interacting with the game, such as `print()`, `entity:SetPos()`, `input()`, `output()`, and many more.
A simple E2 program might read a value from a sensor and display it on a screen. A more complex one could control a fully functional vehicle, manage a complex AI system, or even create custom game modes within the sandbox.
Getting started with E2:
- Spawn an E2 chip.
- Open the editor and write a simple program (e.g., `print('Hello, E2!')`).
- Compile and run the code.
- Experiment with connecting Inputs and Outputs to other entities.
- Refer to the E2 documentation for a comprehensive list of functions and syntax.
While E2 has a learning curve, it offers unparalleled power for creating custom logic and mechanics in Garry's Mod.