Unsolved Having trubble with lua triggers in the world editor

Discussion in 'Mod Support' started by MagKiller111, Oct 21, 2016.

  1. MagKiller111

    MagKiller111
    Expand Collapse

    Joined:
    May 11, 2015
    Messages:
    27
    Hey, I have some problems with the lua triggers and lua commands. I am trying to make a working gas station, so you can drive up to the pumps and then it refuels and we can keep going with full tank. But I am getting some "returned nil value" errors. I have looked thru the wiki and searched for help but can not find anything that helps me. If you need any pictures of the setup or any code, let me know.
     
  2. torsion

    torsion
    Expand Collapse

    Joined:
    May 31, 2015
    Messages:
    1,622
    Are the Lua triggers in the GE Lua (Game Engine Lua) instead of the Vehicle Lua? If so you'll need to pass values back and forth and it could get tricky. Take a look here: http://www.beamng.com/threads/a-way-to-get-a-value-from-system-lua-t3d-lua-gameengine-lua.25139/
    --- Post updated ---
    So it turns out that the triggers are using hooks, which is good. I think that your code should look something like this:
    Code:
    local M = {}
    
    local function onBeamNGTrigger(data)
      if data.event == "your_trigger_name_here" then
        -- this is where we might fill the gas tank
        print("Gas tank filled!")
      end
    end
    
    M.onBeamNGTrigger = onBeamNGTrigger
    
    return M 
     
  3. MagKiller111

    MagKiller111
    Expand Collapse

    Joined:
    May 11, 2015
    Messages:
    27
    Thank you for replying, but this didnt work. I used the code you sent and got this error: http://prntscr.com/cxk2ka in the console.
     
  4. torsion

    torsion
    Expand Collapse

    Joined:
    May 31, 2015
    Messages:
    1,622
    Please attach your Lua file.
     
  5. MagKiller111

    MagKiller111
    Expand Collapse

    Joined:
    May 11, 2015
    Messages:
    27
    I have't added any lua file but I have added the code straight in the worldeditor like this: http://prntscr.com/cxxjw5
     
  6. torsion

    torsion
    Expand Collapse

    Joined:
    May 31, 2015
    Messages:
    1,622
    The example I posted isn't intended to go there. Try using it as a vehicle or game engine lua.
     
  7. MagKiller111

    MagKiller111
    Expand Collapse

    Joined:
    May 11, 2015
    Messages:
    27
    Do you mean using the trigger as GameEngine Lua or Vehicle Lua?
     
  8. torsion

    torsion
    Expand Collapse

    Joined:
    May 31, 2015
    Messages:
    1,622
    The trigger, when properly setup, should generate a hook. This hook should work similarly to onRaceWaypoint(whatever) for example.

    Take a look at heavy_cargo_v2.lua in The Gas Station's Heavy Delivery Pack:Utah scenario pack for an example of how to use a hook like that in a scenario lua. These are all of the hooks used in that Lua: onScenarioRestarted, OnScenarioLoaded, onRaceTick, onRaceWaypoint, onRaceStart, onScenarioChange. You can see where all of those are defined at the bottom of the file.

    Scenario lua files run inside the GE Lua.
     
  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