Changing levels with lua triggers

Discussion in 'Programming' started by SuperAgentAlex, Jan 21, 2024.

  1. SuperAgentAlex

    SuperAgentAlex
    Expand Collapse

    Joined:
    Apr 23, 2020
    Messages:
    567
    How would I change levels using lua triggers?
    I tried to ask ChatGPT for a lua snippet and got this
    function startGridMapLevel()
    return 'beamng.sendGameEngine(\'startLevel("levels/GridMap/GridMap.mis");\')'
    end
    which turned out to be invalid enough to crash the game. Any help?
     
  2. EUDM fanboy

    EUDM fanboy
    Expand Collapse

    Joined:
    Nov 30, 2023
    Messages:
    1,180
    Why. Would you ask chatgpt for lua code?
     
    • Like Like x 1
  3. SuperAgentAlex

    SuperAgentAlex
    Expand Collapse

    Joined:
    Apr 23, 2020
    Messages:
    567
    because I hardly know shit about coding beyond making scratch projects for fun
     
    • Like Like x 1
  4. daniel-w

    daniel-w
    Expand Collapse
    BeamNG Team

    Joined:
    Jan 28, 2017
    Messages:
    282
    Lmao that's brilliant, I wonder what causes the crash, I'm intrigued.
    And to start a level, you do this:
    Code:
    core_levels.startLevel("/levels/west_coast_usa/main.level.json") -- replace west_coast_usa with the map name
    
    To find things like this, open the lua directory in the game's installation folder. Within that folder are hundreds of files, you can open the folder in an editor and browse through. So just think of what something would be called and then search for it (startLevel for example)
     
    • Like Like x 1
  5. uncommoncreations

    uncommoncreations
    Expand Collapse

    Joined:
    Nov 13, 2023
    Messages:
    44
    I Lolled @ that
     
    • Agree Agree x 1
  6. daniel-w

    daniel-w
    Expand Collapse
    BeamNG Team

    Joined:
    Jan 28, 2017
    Messages:
    282
    Yeah, not the best idea to ask ChatGPT about programming, especially for games. It's not the best lol
     
  7. SuperAgentAlex

    SuperAgentAlex
    Expand Collapse

    Joined:
    Apr 23, 2020
    Messages:
    567
    COMPLICATION TIME: I need it for a map I'm making in an 8 year old version of beam (0.3.7.4) (I'm doing it for fun and your answer will help when I port the map to latest)
     
  8. SuperAgentAlex

    SuperAgentAlex
    Expand Collapse

    Joined:
    Apr 23, 2020
    Messages:
    567
    Update:
    I figured out how to load levels via the console (the function is loadLevel( "level path" )) but it still crashes the game when I try to use that same thing on a trigger
     
  9. daniel-w

    daniel-w
    Expand Collapse
    BeamNG Team

    Joined:
    Jan 28, 2017
    Messages:
    282
    You might be using the trigger incorrectly? How are you doing it, map editor or all Lua?
     
  10. SuperAgentAlex

    SuperAgentAlex
    Expand Collapse

    Joined:
    Apr 23, 2020
    Messages:
    567
    Please note that this is all in BeamNG.drive version 0.3.7.4.
    I was trying to use the Trigger instead of the BeamNG Trigger. I think the default T3D trigger is just glitchy, like the lightning entity that also crashes the game. It's all in the map editor, though.
    --- Post updated ---
    I can't seem to get the beamng trigger to work, but I did find a lua function called clientStartMission('levels/level/thelevel')
    --- Post updated ---
    is this code any good?

    local function startTheLevel(thelevel)
    gameEngine:loadLevel( thelevel )
    end
    startTheLevel('levels/GridMap/GridMap.mis')
    end
     
  11. tdev

    tdev
    Expand Collapse
    Developer
    BeamNG Team

    Joined:
    Aug 3, 2012
    Messages:
    3,074
    You could try to queue the command to itself, maybe that fixes the crash, so the level loading does not happen in the trigger:

    Code:
    be:queueLuaCommand('print("hello world")')
     
  12. SuperAgentAlex

    SuperAgentAlex
    Expand Collapse

    Joined:
    Apr 23, 2020
    Messages:
    567
    I don't think that did much (maybe it's because of how old this version of the game is)
    upload_2024-1-23_13-38-39.png
    --- Post updated ---
    it's actually so old that the torque triggers still exist
     
  13. daniel-w

    daniel-w
    Expand Collapse
    BeamNG Team

    Joined:
    Jan 28, 2017
    Messages:
    282
    Oh, yeah.. Which version is it? I can maybe take a look later if I have it downloaded.
     
  14. SuperAgentAlex

    SuperAgentAlex
    Expand Collapse

    Joined:
    Apr 23, 2020
    Messages:
    567
    0.3.7.4, as mentioned in some messages above
     
  15. SuperAgentAlex

    SuperAgentAlex
    Expand Collapse

    Joined:
    Apr 23, 2020
    Messages:
    567
    because of the technical difficulties encountered when trying to add level change triggers, they will not be added in the 0.3-compatible version of the map. they will be present in the version of the map built for the latest version of the game, however.

    this means the latest version of the map will functionally be significantly larger than the 0.3-compatible version
     
  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