Another noob simple questions thread

Discussion in 'Programming' started by Q_Hung, Nov 15, 2021.

  1. Q_Hung

    Q_Hung
    Expand Collapse

    Joined:
    Jul 2, 2021
    Messages:
    21
    Hi all,

    Your local noob has returned with another question which should, I hope, have a very simple answer. I've been tied up with a pretty extreme season at the workplace for the last couple months, but thankfully things are beginning to abate a bit and I can get back into my crazy Beam project.

    I've got a lua file which is just a series of data entries, organized in the typical "function call with a table of arguments" format, with a parser in my main controller file. The controller has been successfully "required" into the project and is accessible from the lua console.

    I'm trying to execute a "dofile()" within the controller to read the entries in, but I'm getting a "no such file exists" error in the console. I simply can't find where to put the data file so that the call works. Said another way: where is the lua "root" in Beam?

    Thanks! I'm very pleased to be back here with you all.

    Q
     
  2. angelo234

    angelo234
    Expand Collapse
    Programmer
    BeamNG Team

    Joined:
    Aug 11, 2017
    Messages:
    540
    The "root" folder is located in your "user folder" and is "/BeamNG.drive/0.23/"
     
  3. Q_Hung

    Q_Hung
    Expand Collapse

    Joined:
    Jul 2, 2021
    Messages:
    21
    Thank you! This works. Another small roadblock down, moving forward.

    Q
     
  4. Q_Hung

    Q_Hung
    Expand Collapse

    Joined:
    Jul 2, 2021
    Messages:
    21
    Alrighty, another kinda weird situation. I took some screenshots of the whole thing but can't get them to post here, so I'll describe the best I can.

    In chasing down some bugs, I've come upon the need to log to the console, so I've begun using the log() function. It's been a disaster from the first moment. I'm getting an error which says "attempt to concatenate local 'origin' (a nil value)". I have not declared nor am I using any local variable called 'origin'. It's included with a variable called 'msg', both nil, in the traceback, and neither of these values are things that I have been concerned with until now.

    I'm putting together a string called 'logStr' with the log message in it, then calling log(logStr)

    Thanks everyone!

    Q
     
    #4 Q_Hung, Nov 18, 2021
    Last edited: Nov 18, 2021
  5. angelo234

    angelo234
    Expand Collapse
    Programmer
    BeamNG Team

    Joined:
    Aug 11, 2017
    Messages:
    540
    Not sure why you're having problems but this is how you use the log function:
    Code:
    log(msg_type_str, origin_of_error_str, message_str)
    Where:
    • msg_type_str is a string designating the 'type' of message displayed and colors the printed message accordingly (e.g. "W" for warning, "E" for error, "I" for information)
    • origin_of_error_str is a string of the origin of the message (e.g. what file/function the message is being sent from)
    • message_str is a string of the message to display
     
  6. Agent_Y

    Agent_Y
    Expand Collapse
    Jbeam/QA support
    BeamNG Team

    Joined:
    Jul 10, 2020
    Messages:
    10,058
    There is a logger template hidden in the game files: Steam\steamapps\common\BeamNG.drive\lua\vehicle\controller\loggerTemplate.lua, maybe this will help you?
     
  7. Q_Hung

    Q_Hung
    Expand Collapse

    Joined:
    Jul 2, 2021
    Messages:
    21
    Thank you, this has to be it. I'm not calling log() correctly. There is a reference to the function somewhere in the (severely limited) online Beam Lua docs, and it looked like it was recommending log (str), so I've just been calling it with one argument. This explains the "origin" and "msg" locals being nil, as I'm never setting the other two arguments on function call. It's so tedious doing development like this, where it takes a day of searching and asking just to accomplish something as simple as logging to the console.

    Appreciated, onwards -

    Q
    --- Post updated ---


    Angelo, can you supply a link to the place you got that information? Or is it something you're gleaning from the system's lua files? Perhaps I'm simply not finding the correct place to look into these "noob" issues I'm having.

    Thanks, Q
     
    • Like Like x 1
  8. angelo234

    angelo234
    Expand Collapse
    Programmer
    BeamNG Team

    Joined:
    Aug 11, 2017
    Messages:
    540
    Just like you said there is no official place to find out how to call these functions :( So I just use a file text searching program (Agent Ransack) to search through the Lua source code for the game to find examples of how to call the functions I want to call. Once you get used to doing it this way, it actually isn't too bad lol. Also I've made this website that lists out most of the available functions you can find which can help you too: https://angelo234.github.io/List-of-BeamNG-Functions-And-Fields/index.html
     
  9. Q_Hung

    Q_Hung
    Expand Collapse

    Joined:
    Jul 2, 2021
    Messages:
    21
    I hope this thread (and the other one from a few months ago) are helpful to other less-experienced programmers like myself. There's just so much simple stuff that's giving me headaches, and I'm guessing that I'm not the only one. I wouldn't even be pursuing this if I didn't think the end product is going to be very much worth it.

    So, here's today's simple noob issue: I am now trying to access the X/Y/Z coordinates of a Point Of Interest. I've used a large number of these points to define locations within the map, and I'm now trying to load and parse the data. All is going well except that I can't get at the actual numbers - I don't think I'm referencing them correctly.

    I've tried using pointOfInterest.x, as well as pointOfInterest.position.x - I'm getting 'nil' returns on these so it seems I'm looking for them in the wrong place. Do I need to use something like pointOfInterest.position.point3F.x? I once again feel like I'm lost in the middle of my own hometown.

    Bookmarked! That's a great list. : ) I'll check out Agent Ransack, hopefully today.

    Thanks,

    Q
     
  10. angelo234

    angelo234
    Expand Collapse
    Programmer
    BeamNG Team

    Joined:
    Aug 11, 2017
    Messages:
    540
    You're pretty close :) But this is how you do it:
    Code:
    vec3(pointOfInterest:getPosition())
    FYI you can also use the following code to print out what functions a Lua userdata object (represents a C/C++ object) has:
    Code:
    dump(getmetatable(user_data_obj))
    So this for example will print out all the functions that this scene object contains like getPosition():
    Code:
    dump(getmetatable(scenetree.findObject("object_name")))
     
  11. Q_Hung

    Q_Hung
    Expand Collapse

    Joined:
    Jul 2, 2021
    Messages:
    21
    Again, thank you. This works perfectly, and I'm moving forward once again. Getting very close to having my full circuit metadata file parsed and resident in memory. I would be dead in the water without your help, and the help of the rest of the community.

    Hoping to make some serious progress today without leaning on you and the forums for every little step. Every morsel of information you've given me is like gold.

    Q
     
    • 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