Solved A way to get a value from System Lua, T3D Lua, GameEngine Lua?

Discussion in 'Mod Support' started by StinchinStein, May 11, 2016.

  1. StinchinStein

    StinchinStein
    Expand Collapse

    Joined:
    Jul 16, 2014
    Messages:
    754
    Hey, I was wondering if there was a way to get a value from the system lua, game engine lua, and T3D lua into vehicle lua, I saw at one point someone did (in this thread):

    Code:
    local cmd = obj:queueLuaCommand('return value')
    Then did this to retrieve the value:

    Code:
    local val = obj:getLuaResult(cmd)
    but that's only for T3D Lua (I believe), but even then I can't figure out how to get it to actually return a value.

    I also saw that you can do obj:queueGameEngineLua() to run game engine lua from vehicle lua, but it doesn't return a value.

    The only reason I ask is because I want to figure out a way to find the version of BeamNG.drive, so if it gets an update, my mod will auto-disable itself.

    If there is an easier way to find the version of BeamNG.drive in vehicle lua, please do tell! :)

    Thanks,
    StinchinStein

    P.S. I'm guessing only the dev's would know how to answer this, but I might be wrong.
     
    #1 StinchinStein, May 11, 2016
    Last edited: May 11, 2016
  2. meywue

    meywue
    Expand Collapse
    Administrator
    BeamNG Team

    Joined:
    Nov 19, 2015
    Messages:
    339
    Hey,

    there's actually no easy solution. The problem is that there're several virtual machine for the lua code. For example we have a gameengine virtual machine, a vehicle virtual machine etc.

    So if you execute your code within the game engine virtual machine your code needs to look like this:

    Code:
    be:getPlayerVehicle(0):queueLuaCommand("obj:queueGameEngineLua('myValue = ('..electrics.values['fuel']..')')")
    It's a bit like ping pong. You execute code from game engine lua to execute vehicle lua code to pass the value to game engine lua again.
    The other side of the shield is that it's not executed in 'real time' since your queuing the commands.
     
    • Like Like x 1
  3. StinchinStein

    StinchinStein
    Expand Collapse

    Joined:
    Jul 16, 2014
    Messages:
    754
    How would I go about doing this for getting GameEngine Lua values in VLua? If it's not possible, that's fine.
     
  4. torsion

    torsion
    Expand Collapse

    Joined:
    May 31, 2015
    Messages:
    1,600
    It's possible. Can you post a specific example of what you want to do? eg the name of a variable you want to get back into vlua
    --- Post updated ---
    OK, I thought of an example variable in GE Lua, so here is some (tested) code which works:
    Code:
    obj:queueGameEngineLua("be:getPlayerVehicle(0):queueLuaCommand('torsionTest = (\"'..Steam.playerName..'\")')")
    Note that we're dealing with a string here. If you were dealing with a non-string something different might need to be done.
     
    • Like Like x 3
  5. StinchinStein

    StinchinStein
    Expand Collapse

    Joined:
    Jul 16, 2014
    Messages:
    754
    Thanks, this is exactly what I wanted ;)
     
  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