Help with accessing electrics

Discussion in 'Programming' started by oKempi, Jun 24, 2024.

  1. oKempi

    oKempi
    Expand Collapse

    Joined:
    Jun 24, 2024
    Messages:
    1
    Before you read this, please keep in mind that I'm completely new to modding beamng drive and also lua (although I have some experience with programming mostly python)
    My problem is that I can not access (and also don't know how to) electrics (the module?).
    This means when I write (and please correct me if I wrote it wrong which I almost certainly did) for example: "print(electrics.rpmTacho" it just says that it couldn't find such a thing as electrics and tries to find it in close directories.
    I have also tried opening it through the exact file directory path pointing to the lua file.

    So if you know how to help please do so!
     
  2. r3eckon

    r3eckon
    Expand Collapse

    Joined:
    Jun 15, 2013
    Messages:
    595
    When trying to access scripts that are in lua/vehicle make sure you select a vehicle in the console dropdown. In BeamNG vehicles are running their own instance of lua so if you send the command to "GE - Lua" which is the default instance selected in console it won't find vehicle related scripts.

    upload_2024-6-25_23-21-43.png

    The correct command to print rpmTacho is print(electrics.values.rpmTacho) which works as expected when sent to a vehicle instance:

    upload_2024-6-25_23-32-4.png

    If you're confused about how to access certain values from scripts try for example dump(electrics) this will show you all accessible values:

    upload_2024-6-25_23-34-19.png

    If you're trying to access vehicle values from game engine lua scripts without using console you need to use be:getObjectByID(vehid):queueLuaCommand("...") on the GE side and then from the vehicle side obj:queueGameEngineLua("..."). This is a bit confusing but basically a game engine script can call vehicle instance commands and vehicles can "respond" by calling game engine lua. You can use this to pass information between instances. For example this line executed from GE will print the rpmTacho value for the vehicle with ID 39599:

    be:getObjectByID(39599):queueLuaCommand("obj:queueGameEngineLua(string.format('print(%s)', electrics.values.rpmTacho))")

    upload_2024-6-25_23-42-25.png
     

    Attached Files:

    • upload_2024-6-25_23-32-20.png
    • Like Like x 1
  3. stenyak

    stenyak
    Expand Collapse
    Programmer & Global Moderator
    BeamNG Team

    Joined:
    Aug 6, 2012
    Messages:
    2,014
    @oKempi FYI there's a bit of documentation on that ^ topic here: https://documentation.beamng.com/modding/programming/virtualmachines/
     
    • 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