"Hello World"

Discussion in 'Programming' started by NuclearKnight, Dec 26, 2021.

  1. NuclearKnight

    NuclearKnight
    Expand Collapse

    Joined:
    Nov 30, 2013
    Messages:
    64
    Need some help getting started with some basics in lua mods. So, I have this code:

    M = {}

    local function updateGFX(dt)
    print("Hello")
    end

    M.updateGFX = updateGFX

    return M

    From my limited understanding, this should make the console print out "hello" every frame but it doesn't.
    As for my file structure, I have tried putting this file in "myscript/lua/vehicle/extenstions/myscript" , "myscript/ge/extensions/myscript", and putting it in "myscript/scripts/myscript/myscript" and loading with modScript file.

    I have also tried running it in the repo and as unpacked. I have gotten quite a few personal scripts working on my BeamMP servers so I have a good grasp on how lua works but I can't get this to work I must be missing something stupidly obvious. Thanks in advance for any help.
     
  2. StinchinStein

    StinchinStein
    Expand Collapse

    Joined:
    Jul 16, 2014
    Messages:
    754
    I believe the updateGFX function is only available on the vlua side of game. The Lua environments are split between game engine (ge) and vehicle (vlua).

    There are, however, a few functions available in the game engine Lua that you can use (found in Steam\steamapps\common\BeamNG.drive\lua\ge\main.lua):
    • onPreRender (this function is called right before the rendering, and after running the physics)
    • onFirstUpdate (first update, only run once at the beginning of the physics as far as I know)
    • onUpdate (this function is called after input and before physics)
    • onGuiUpdate (supposedly called when the GUI updates in the game)
    Here's 2 of the functions available in vlua as well that are called repeatedly:
    • updateGFX (called every graphics frame)
    • onDebugDraw (called for debug rendering)
     
    • Like Like x 1
  3. NuclearKnight

    NuclearKnight
    Expand Collapse

    Joined:
    Nov 30, 2013
    Messages:
    64
    Thanks for the reply, do you mind clarifying what this means in regards to my scripts? In other words, how can I make a script that will run on each frame update?
     
  4. StinchinStein

    StinchinStein
    Expand Collapse

    Joined:
    Jul 16, 2014
    Messages:
    754
    You would have to create a script in the vehicle lua side of the game for it to run each frame.

    To do this you would have to make it in the folder "BeamNG.drive/lua/vehicle/extensions/auto" (or for the mods folder: "mods/unpacked/<modname>/lua/vehicle/extensions/auto"

    Code:
    local M = {}
    
    local function updateGFX(dt)
        print("Hello World")
    end
    
    M.updateGFX = updateGFX
    return M
    (I've attached a barebones example mod below)
     

    Attached Files:

    • Like Like x 2
  5. NuclearKnight

    NuclearKnight
    Expand Collapse

    Joined:
    Nov 30, 2013
    Messages:
    64
    I think at one point I did have it in that path although I may have forgotten the "auto" folder so I'll try that later and see what happens thank you!
     
    • Like Like x 1
  6. NuclearKnight

    NuclearKnight
    Expand Collapse

    Joined:
    Nov 30, 2013
    Messages:
    64
    Yep it worked only as unpacked though thank you!
     
    • Like Like x 1
  7. NuclearKnight

    NuclearKnight
    Expand Collapse

    Joined:
    Nov 30, 2013
    Messages:
    64
    Alright, so I've gotten some things to work but how do I get the mod to work after I pack it?
    --- Post updated ---
    Nevermind, I got it working in the repo just gotta figure out how to get it to work in MP.
     
  8. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,514
    How did ever came up with this ?? I've been looking around thru the game files and found this criteria nowhere :D
     
    • Agree Agree x 1
  9. StinchinStein

    StinchinStein
    Expand Collapse

    Joined:
    Jul 16, 2014
    Messages:
    754
    upload_2021-12-29_18-2-21.png

    Found in lua/vehicle/main.lua

    I've known about it for a couple years now, read it here when it was first posted.
    I also look through BeamNG.drive's code... A LOT ;)
     
    • Like Like x 1
  10. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,514
    Nice ! That's super cool :)
    Thanks for explaining !
     
    • 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