Solved Set electrics.values within javascript

Discussion in 'Mod Support' started by aljowen, Jun 6, 2017.

  1. aljowen

    aljowen
    Expand Collapse

    Joined:
    Oct 21, 2012
    Messages:
    1,677
    Is it possible to set electrics.values from within the javascript?

    My car has a dashboard menu system, this has been created in JavaScript inside the HTML file. I was wanting to add in cruise control and hill descent assist.
    I have tried returning values from the JavaScript but wasn't able to get that to work. Maybe there is some pointer/passByRef magic that can be done?

    If it isn't possible its not too big of a deal, I can move all the logic into Lua and make everything a function call to JavaScript. Just a little more work that way.

    On a slight side note, do function calls from Lua to JavaScript pose any performance issues?

    Cheers for any help :)
     
  2. thomatoes50

    thomatoes50
    Expand Collapse
    BeamNG Team

    Joined:
    Jan 31, 2013
    Messages:
    722
    To set electric value you can do this
    Code:
    bngApi.activeObjectLua('electrics.values.potatoes = 1');
    but what you should do is:
    yourVehicule/lua/yourModule.lua
    Code:
    bngApi.activeObjectLua( 'yourModule.setCC(' + speed + ')' );
    there will be not much performance issue because commands are queued. There will be a small delay but not much

    The Cruise control logic should be in the lua side because it will have the latest values from the car
     
  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