Solved Lua syntax + BeamNG variable help

Discussion in 'Mod Support' started by torsion, Aug 20, 2016.

  1. torsion

    torsion
    Expand Collapse

    Joined:
    May 31, 2015
    Messages:
    1,600
    I know that I have a poor grasp of these concepts, so I apologize in advance.

    Please help me understand this command in more detail, beyond the scope already explained in this post:
    Code:
    be:getPlayerVehicle(0):queueLuaCommand("obj:queueGameEngineLua('myValue = ('..electrics.values['fuel']..')')")
    
    I understand the general purpose of the code - it should set a variable in one VM to a value found in another VM. I've read that the colon operator makes be:getPlayerVehicle(0) the equivalent of be.getPlayerVehicle(be,0) in the Lua docs.

    I could really use some more handholding though:
    1. What is the "be" variable? (BeamEngine? Why does this need the colon operator instead of just a period?)
    2. What is the "obj" variable? What is it doing for us here?
    3. I'm a little confused by the repeated use of the colon operator. Maybe it's not doing what I think it's doing here?
    4. The example code is for copying the value of electrics.values.fuel in the Vehicle Lua VM over to myValue in the GE Lua VM... right?
    5. I simply don't understand how this code copies the data from one VM to another. Please give more details on what the code is doing to achieve that. Walking me through what happens step by step would be useful.
    6. EDIT: Maybe I just need help detangling all the nested quotes? Maybe everything would be clear if I had a handle on that?
     
  2. Dummiesman

    Dummiesman
    Expand Collapse

    Joined:
    Sep 17, 2013
    Messages:
    4,682
    As for the colon , see this : http://stackoverflow.com/a/4911217/2377834

    As for the rest:
    be is indeed BeamEngine
    obj represents the vehicle
    obj:queueGameEngineLua executes code on the game engine side. In this case, it sets a global variable myValue inside of the game engine Lua.
     
    • Like Like x 3
  3. torsion

    torsion
    Expand Collapse

    Joined:
    May 31, 2015
    Messages:
    1,600
    Thanks Dummiesman. That helped! I still don't have a strong handle on the colon operator. It is easy to understand precisely what it does, my trouble comes from why we need to do it in some cases. It seems to be related to an OO concept which I don't know about or comprehend. :-/

    In cases like the example I can become very confused by concatenation. After I took the guts of the double-quoted section out and put it on it's own line syntax highlighting kicked in and helped me figure out what was going on with that. :)

    It especially helped that you mentioned that "obj" represents the vehicle.

    EDIT:
    To clarify for anyone else who comes to this thread looking for answers - working in VM (a) we concatenate a variable from VM (a) into the command to assign a value to a variable in VM (b). So when the command runs in VM (b) it's not an assignment from one variable to another - it's assigning a static value to the variable. (eg the static value between the concatenation operators "..")
     
    • 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