Ye Olde Meme Game 2 Modding Documentation

website·Indexed 31 days ago

https://mods.yomg2.etggames.com

Guides and API reference for ModScripting in Ye Olde Meme Game 2. Learn how to use Lua and MoonSharp to create mods, handle lifecycle events, manage static types, and implement coroutines within the Unity-based game structure.

Tokens
10.2K
Snippets
44
Records
76
Agent score
49%

What's inside Ye Olde Meme Game 2

  1. Introduction to ModScripting in Ye Olde Meme Game 2

    ModScripting allows users to create custom levels in Ye Olde Meme Game 2 using the Lua programming language. The system is designed for beginners and provides an in-game API reference with copy-pasteable examples, tutorials, and a community of shared mods to help users get started.
  2. Overview of ModScripting in Ye Olde Meme Game 2

    Ye Olde Meme Game 2 (YOMG2) features 'ModScripting', a system accessible via the 'experimental mode' option within the Level Builder. ModScripting allows users to write code to manipulate game elements by exposing much of the underlying Unity Game Engine code, providing high flexibility for level design and game modification.
  3. Understand the role of Unity and C# in modding

    Ye Olde Meme Game 2 is developed using the Unity game engine. While not strictly required for basic modding, familiarity with Unity components and the C# programming language is highly beneficial for accessing, modifying, and destroying game components and for understanding the API Reference.
  4. Use the Community Mods panel to find and share ModScripts

    All ModScripts from published levels are automatically uploaded to the Community Mods panel. This panel allows developers to discover existing scripts and share their own. To avoid duplicate uploads of the same script, the system uses a unique script hash for identification. Because code is shared automatically, developers are encouraged to keep their ModScripts clean and understandable for others.
  5. Understand C# collection to Lua table conversion

    MoonSharp automatically converts commonly used C# collections (like List<T>) into Lua tables and vice versa. This allows developers to use Lua paradigms (like ipairs) to iterate over data returned from C# functions. To maintain compatibility with other ModScripts, it is recommended to stick to Lua tables whenever possible.
    local illuminatis = getItemsByMemeId("Illuminati") -- returns a C# List<GameObject> converted to a Lua table
    for i, item in ipairs(illuminatis) do
        -- process item
    end
  6. Use the in-game API Reference for ModScripts

    The API Reference is an auto-generated, interactive in-game tool used to discover available members for ModScripts. It is organized into four primary columns:

    1. MemeItems: A list of all retrieveable MemeItems in the game.
    2. GameObject Hierarchy: The parent and child GameObject structure of the selected MemeItem.
    3. Components: All Components attached to the selected GameObject.
    4. Members: All member variables (fields and properties), methods, and events available on the selected Component.
  7. Understand Unity's GameObject and Component system

    In Unity, every object in a scene is a GameObject. Behavior is defined by Components attached to these GameObjects. A Component is a C# class containing data (member variables) and functions (member methods). GameObjects can be nested in a hierarchy, where child GameObjects inherit position, rotation, and size from their parent.
    // Example of calling a member method on a Rigidbody2D component
    playerRigidbody.AddForce(new Vector2(69, 420));
  8. Utilize API Reference helper features

    The API Reference includes several utility features to speed up development:

    • Detailed Type Info: Types underlined in dark blue are clickable, providing more detailed information about that specific type.
    • Auto-generated Examples: Every member provides a boilerplate code snippet that can be copied into a ModScript. These examples typically demonstrate how to print the member's value to the console.
    • Unity Documentation: Some members provide direct buttons to open the corresponding official Unity documentation.

    Note: Because the reference and examples are auto-generated, they may occasionally contain inaccuracies.

  9. Interact with Unity Components via ModScripts

    To manipulate game objects from a ModScript, follow this access chain:

    1. Retrieve a MemeItem from the level.
    2. Access the desired parent or child GameObject on that MemeItem.
    3. Access the specific Component attached to that GameObject.
    4. Interact with the component's member variables or methods.
  10. Access static members in Moonsharp ModScripts

    In Moonsharp, static members of a type are accessed through an instance of that type rather than the class name. For types that can be constructed (like structs), you must create an instance first. For reference types (classes) that cannot be constructed in ModScript, the environment provides pre-instantiated global objects for commonly used Unity types.
    -- Example: Accessing Vector2.Distance (C#) in ModScript
    local dummyVector2 = createInstance("Vector2")
    local pointA, pointB = createInstance("Vector2"), createInstance("Vector2")
    
    pointA.x, pointA.y = 6, 9
    pointB.x, pointB.y = 4, 2
    
    -- Access static method Distance via the dummy instance
    local distance = dummyVector2.Distance(pointA, pointB)
    print("distance: ", distance)
  11. Use the YOMG2 Modding Assistant for ModScripts

    The YOMG2 Modding Assistant (and general ChatGPT) is recommended for writing ModScripts. The assistant is specifically trained on the modding documentation, tutorials, Unity, C#, Lua, and MoonSharp.
  12. Subscribe to and handle events in ModScripts

    Events in ModScripts allow you to execute code in reaction to game occurrences. An event handler function must accept two parameters: sender (the C# object that raised the event) and eventArgs (an object containing event-specific data). To subscribe, use the .add() method on the event member. Note that events must follow the standard EventHandler pattern and meet MoonSharp's event requirements.
    registerType("HealthChangedEventArgs")
    registerType("IHasHealth")
    registerType("Player")
    registerType("Vector3")
    
    local healthComponent = getCurrentItem().GetComponent("IHasHealth")
    
    -- The event handler function
    function healthChangedHandler(sender, eventArgs)
        local scale = healthComponent.transform.localScale
        local healthDecrease = eventArgs.OldHealth - eventArgs.NewHealth
        scale.x = scale.x + (0.069 * healthDecrease * Mathf.Sign(scale.x))
        healthComponent.transform.localScale = scale
    end
    
    -- Subscribing to the event
    healthComponent.HealthChanged.add(healthChangedHandler)