1. Stuck, Having problems with creating your mod? Let us help you: Mod Support

Solved Get value of lua in javascript

Discussion in 'Mod Support' started by HDR, Nov 1, 2018.

  1. HDR

    HDR
    Expand Collapse

    Joined:
    Oct 15, 2015
    Messages:
    233
    Hi, just wondering if anyone has a good solution of getting values from lua in javascript.


    To be specific, getting color palettes from lua and using that as a variable in Javascript.

    Code:
    TorqueScript.eval([[getVehicleColorPalette(0);]])
    
     
  2. Vaasik

    Vaasik
    Expand Collapse

    Joined:
    Aug 6, 2012
    Messages:
    16
    In order to get the value from a Lua function it needs to return some value:
    Code:
    local function getVehicleColorPalette()
      return someVehicleColorPalette
    end
    
    Then in JS you will need to call the Lua function and it will return the value:
    Code:
    bngApi.engineLua('my_extension.getVehicleColorPalette()', function(data) {
      // assign value returned from Lua
      var returnedValue = data;
    });
    
     
    • Like Like x 1
  3. HDR

    HDR
    Expand Collapse

    Joined:
    Oct 15, 2015
    Messages:
    233
    upload_2018-11-2_16-49-23.png

    I feel kind of stupid right now haha, thanks for the help :)
     
  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