Unsolved Some lua troubles

Discussion in 'Mod Support' started by TunerFromHell, Apr 2, 2023.

  1. TunerFromHell

    TunerFromHell
    Expand Collapse

    Joined:
    Jan 11, 2022
    Messages:
    127
    I literally know nothing about lua scripts, but I want to make "active" aerodynamic.
    By pressing G, variable "downforceR" changes to variable "downforceR2" and back if button was pressed again. keyboard.json is working, so trouble is with .lua file.

    I tried ChatGPT, but it gave me some stupid answers which broke my mod, so I watched how it's done in FR17 mod. Result:

    local M = {}

    local function onInit()
    electrics.values['Downforce'] = 0
    electrics.values.downforce = 0
    end

    local function onReset()
    onInit()
    end

    local function toggle(dt)
    if electrics.values.downforce < 1 then
    gui.message("100")
    else
    gui.message("1000")
    end
    end


    M.onInit = onInit
    M.onReset = reset
    M.toggle = toggle

    return M


    Im only testing this script, so func toggle is wip (gui.message will show if script works). In FR17 mod DRS is completely different idea from mine, so I ran into some roadblocks coding this script. Btw here is input_actions.json:

    {
    "toggle_downforce":{"order": 1, "onDown":"electrics.values.downforce = 1-(electrics.values.downforce or 0)", "title": "Toggle Aerodynamics", "desc": "Toggle Aerodynamics." }
    }


    In theory, in .jbeam file will be 2 variables, and they'll change, when electrics.values['Downforce'] will change. But it's not working, because im a noob in .lua files. If somebody knows how to write it or how to help me, plz write here.

    P.S. Don't be afraid to tell me that I'm dumb at coding, I'll appreciate any critic. And sorry for grammar mistakes, english is not my native lang)
     
  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