1. Trouble with the game?
    Try the troubleshooter!

    Dismiss Notice
  2. Issues with the game?
    Check the Known Issues list before reporting!

    Dismiss Notice
  3. Before reporting issues or bugs, please check the up-to-date Bug Reporting Thread for the current version.
    0.32 Bug Reporting thread
    Solutions and more information may already be available.

Simple Speedometer - lua scripting

Discussion in 'Troubleshooting: Bugs, Questions and Support' started by Nadeox1, Aug 6, 2013.

  1. Nadeox1

    Nadeox1
    Expand Collapse
    Spinning Cube
    BeamNG Team

    Joined:
    Aug 5, 2012
    Messages:
    14,686
    I'd like to code some kind of very basic Speedometer so it prints out the current vehicle speed on the screen.
    I think it could be done using lua, but I never tried lua, so I wanted to know where I could get my reference to try coding one. Thanks :)
     
  2. Incognito

    Incognito
    Expand Collapse

    Joined:
    Aug 4, 2013
    Messages:
    246
    You can find some syntax examples in the wiki: http://wiki.beamng.com/Lua . If you have any programming skills in some language that you can easily learn/understand lua.

    P.S. I did a simple speedometer by changing the game files: adding another debug screen. But this is not the best solution, i think.
    Need to wait documentation in which will be described how correctly writing own scripts for BeamNG Sandbox.
    P.S. This is a simple speedometer:
    1. Open lua\vehicle\bdebug.lua , found
    Code:
    local modeCount = 12
    and change 12 to 13:
    Code:
    local modeCount = 13
    In this file after
    Code:
    elseif M.mode == 12 then
            txt = "Lua Performance Debug"
    add:
    Code:
    elseif M.mode == 13 then
            txt = "Speedometer"
    2. Open lua\vehicle\canvas.lua and after
    Code:
    self:drawLuaPerf(dt)
    add
    Code:
    elseif modeNumber == 13 then
            self:showSM(dt)
    Then after end of the DrawingCanvas:update function add
    Code:
    function DrawingCanvas:showSM(dt)
        self.ct:clear()
    
        if not self.debugCounter then
            self.debugCounter = 0
        end
    
        self.debugCounter = self.debugCounter + 1
        if self.debugCounter > 32000 then self.debugCounter = 0 end
    
        local airspeed = obj:getVelocity():length()
        local txt = "airspeed: " .. math.floor(airspeed * 3.6) .. " km/h, " .. math.floor(airspeed * 2.23694) .. " mp/h"
        self.c:drawText(txt, string.len(txt), 5, 70, self.paints.fontLeft)
    end
    After these changes will be added 13 debug screen, where will be only a vehicle speed (and some debug info).
     

    Attached Files:

    • 2013-08-06_00001.jpg
    • sm.rar

      File size:
      10 KB
      Views:
      171
    #2 Incognito, Aug 6, 2013
    Last edited: Aug 6, 2013
  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