M.engineInfo vs simpleGears UI app

Discussion in 'Programming' started by NOCARGO, Aug 29, 2021.

  1. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,514
    I don't get stuck too often, but rebuilding my custom gear app is giving me trouble this time.
    Below an example of unmodified code ↓

    vehicleController :
    Code:
    if streams.willSend("engineInfo") then
        M.engineInfo[1] = controlLogicModule.idleRPM or 0
        M.engineInfo[2] = controlLogicModule.maxRPM or 0
        M.engineInfo[5] = controlLogicModule.rpm
        M.engineInfo[6] = gearName
        M.engineInfo[7] = controlLogicModule.maxGearIndex or 0
        M.engineInfo[8] = controlLogicModule.minGearIndex or 0
        M.engineInfo[9] = controlLogicModule.flywheelTorque or 0
        M.engineInfo[10] = controlLogicModule.gearboxTorque or 0
        M.engineInfo[11] = obj:getGroundSpeed() -- airspeed
        M.engineInfo[12] = electrics.values.fuelVolume
        M.engineInfo[13] = electrics.values.fuelCapacity
        M.engineInfo[16] = 0
        M.engineInfo[17] = electrics.values.gearIndex
        M.engineInfo[18] = controlLogicModule.isEngineRunning or 1
        M.engineInfo[19] = electrics.values.engineLoad
        M.engineInfo[20] = wheels.wheelTorque
        M.engineInfo[21] = wheels.wheelPower
      end
    simpleGears UI app:
    Code:
    if (streams.engineInfo != null) {
                scope.gearboxType = streams.engineInfo[13];
                if (scope.gearboxType == 'manual') {
                  var mGear = streams.engineInfo[5]
                    , maxFGears = streams.engineInfo[6]
                    , maxRGears = streams.engineInfo[7]
                    , sign = mGear ? (mGear < 0 ? -1 : 1) : 0;
    engineInfo[13]
    controller : fuelCapacity
    app : gearboxType

    engineInfo[5]
    controller : rpm
    app : mGear , which according to me corresponds to 'currentGearIndex' or 'gearIndex' ?

    engineInfo[6]
    controller : gearName
    app : maxFGears

    engineInfo[7]
    controller : maxGearIndex , which according to me corresponds to 4,5 or 6 or 12 etc ?
    app : maxRGears, which according to me corresponds to 1 or 2 (at least for 'vanilla cases' ?

    Any feedback would surely be appreciated :)
    --- Post updated ---
    So far the only thing I can think of is that there is a possibility that the LUA table is read by the JScript in a raw manner and that LUA tables start reading their first index as '0' and JScript reads the first index as '1' so the indexes are stepped but this is a bit too crazy imo :p
     
  2. Diamondback

    Diamondback
    Expand Collapse
    Vehicle Systems Lead
    BeamNG Team

    Joined:
    Apr 8, 2014
    Messages:
    1,957
    Yep, that's exactly what you are looking at. Regular lua arrays start at 1, not 0.
     
    • Like Like x 1
  3. NOCARGO

    NOCARGO
    Expand Collapse

    Joined:
    Apr 1, 2019
    Messages:
    1,514
    Oh.. great ! At least I've got that out of the way then :)
    Thank you, Diamondback !
     
    • 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