Simple mod Lua Script("Hello World")?

Discussion in 'Mod Support' started by CVSSL, Dec 24, 2023.

  1. CVSSL

    CVSSL
    Expand Collapse

    Joined:
    Apr 15, 2023
    Messages:
    1
  2. daniel-w

    daniel-w
    Expand Collapse
    BeamNG Team

    Joined:
    Jan 28, 2017
    Messages:
    284
    You're not doing it correctly. Do the following (Same code and folder structure, create them if they are not there already)

    0.31/mods/unpacked/myMod/ <-- This is where your mods will go
    lua/ge/extensions/ <-- The game uses a thing called "extensions", this is where your entry point will go
    myMod.lua <-- Your magical file​
    scripts/myMod/
    modScript.lua <-- The game will look for this to determine what to load and how
    In "myMod.lua", put the following:
    Code:
    local M = {} -- This is your module (hence the "M")
    
    local function onExtensionLoaded()
        log('D', "onExtensionLoaded", "Called!")
    end
    
    M.onExtensionLoaded = onExtensionLoaded -- We want to expose this to the module so the game can call it
    
    return M -- The game requires the module, so we must return it so the game can access it. That way it can call the "onExtensionLoaded" function
    
    In "modScript.lua", put the following:
    Code:
    load("myMod") -- Load the mod
    setExtensionUnloadMode("myMod", "manual") -- Set the unload mode to manual (This is very new, old function is deprecated)
    
    Hopefully this helps, if not then oh well. Just take a look through the game's scripts to see how it all works :)
     
    • Like Like x 5
  3. moth0001

    moth0001
    Expand Collapse

    Joined:
    Feb 19, 2019
    Messages:
    19
    Thank you, 2pm and I finally found a solution for my problem.
     
  4. daniel-w

    daniel-w
    Expand Collapse
    BeamNG Team

    Joined:
    Jan 28, 2017
    Messages:
    284
    • Like Like x 2
  5. moth0001

    moth0001
    Expand Collapse

    Joined:
    Feb 19, 2019
    Messages:
    19
    Thanks, didn’t knew about that, it’s way better than other sections of the documentation.
     
    • Like Like x 1
  6. daniel-w

    daniel-w
    Expand Collapse
    BeamNG Team

    Joined:
    Jan 28, 2017
    Messages:
    284
    Yeah, it was only recently added
     
    • Like Like x 1
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice