Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-mini-2024-07-18· OpenAIHugging Face LMArena Human Preference 140K

What is expression 2 programming language? give me a comprehensive example

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Geminigemini-2.0-flash-thinking-exp-01-21’s answer.
  1. User

    What is expression 2 programming language? give me a comprehensive example

  2. Assistant

    Expression 2 (E2) is a scripting language used primarily in the context of the Garry's Mod game, which is a sandbox game built on the Source engine. E2 is part of the Expression 2 chip, a component of the Wiremod addon for Garry's Mod. It allows players to create complex logic and behaviors for their creations, such as vehicles, contraptions, and other interactive elements within the game.

    E2 is designed to be user-friendly while still providing powerful programming capabilities. It supports variables, functions, conditionals, loops, and various data types, making it versatile for game development and automation tasks.

    Comprehensive Example of Expression 2

    Here’s a simple example of an Expression 2 script that creates a basic automated door system. The door will open when a player is nearby and close after a certain time.

    @name Automated Door
    @inputs Door:entity Player:entity
    @outputs Open:wirelink
    @persist Timer:float
    @trigger all
    
    if (first()) {
        Timer = 0
        Open = 0
    }
    
    # Check if the player is within a certain distance from the door
    if (Player:isValid() && Door:isValid()) {
        if (Player:pos():distance(Door:pos()) < 100) {
            # Open the door
            Door:setAng(0, 90, 0)  # Rotate the door to open position
            Open = 1
            Timer = 5  # Set timer for how long the door stays open
        }
    }
    
    # If the door is open, start the timer
    if (Open == 1) {
        Timer = Timer - deltaTime  # Decrease timer by the time since last frame
        if (Timer <= 0) {
            # Close the door
            Door:setAng(0, 0, 0)  # Rotate the door back to closed position
            Open = 0
        }
    }
    

    Explanation of the Code

    1. Header Information: The @name and @inputs/@outputs lines define the name of the script and the inputs/outputs it uses. In this case, it takes a Door entity and a Player entity as inputs and outputs a wirelink signal called Open.

    2. Initialization: The if (first()) block initializes the Timer and Open variables when the script first runs.

    3. Distance Check: The script checks if the Player is within 100 units of the Door. If so, it opens the door by changing its angle and sets a timer for how long the door will remain open.

    4. Timer Logic: If the door is open, the script decreases the Timer by the time elapsed since the last frame (deltaTime). Once the timer reaches zero, the door is closed by resetting its angle.

    5. Output: The Open output can be used to trigger other components in the Wiremod system, such as lights or sounds, indicating that the door is open.

    Usage

    To use this script in Garry's Mod:

    1. Install the Wiremod addon if you haven't already.
    2. Create an Expression 2 chip in the game.
    3. Copy and paste the script into the E2 chip's editor.
    4. Link the Door input to a door entity in the game and the Player input to a player entity (usually the local player).
    5. Run the script, and the door should automatically open and close based on the player's proximity.

    This example demonstrates the basic functionality of Expression 2 and how it can be used to create interactive elements in Garry's Mod. The language allows for much more complex logic and interactions, making it a powerful tool for players looking to enhance their gameplay experience.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.