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.
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)
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?
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)
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!
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.
How did ever came up with this ?? I've been looking around thru the game files and found this criteria nowhere
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