Conversation System

Discussion in 'Programming' started by Occam's Razer, Sep 23, 2016.

  1. Occam's Razer

    Occam's Razer
    Expand Collapse

    Joined:
    Aug 7, 2013
    Messages:
    1,152
    Let the boys in the office know they can head home. I've got this week's dumb idea covered.

    Okay so, I'm just gonna dive right into this. I'm trying to make a conversation system for BeamNG, so as to allow for more narrative- and dialogue-driven scenarios and/or campaigns once the latter becomes an option. I know this is a weird thing to want for a driving game, that's why I'm trying to understand how to tackle the problem rather than asking the devs to do it for me as an official feature.

    Anyway, I've got a pretty straightforward idea as to how to make it work in theory, but in my attempts to make a prototype, I've come across two main issues:

    A. I can't seem to get existing inputs via the scenario's .lua file, let alone make my own. To be honest, I'm not even sure that I can create inputs on the fly so this will very much be an instant deal-breaker if the answer is simply no. Otherwise, it seems a lot like I'll need to create my own actionMap and I simply don't know how to do that, or if it might incidentally stop the game's native inputs from working.

    In other words, how do [can] I make and detect a key binding from a scenario .lua?

    B. Display-wise, I've found the 'flashUiMessage' to be a fair option, but since it doesn't allow for line breaks (I've tried, believe me), I think the better way of giving the player the possible responses would be via the messages app. As in, the one that lets you know when your tires have been burst or driveshaft broken. Every possible response would be relegated to its own box, so there would be no confusing the other party's statement and your reply(s). While I did find code for this in the game's core vehicle files, I get the sensation that vehicle-related files are more directly tied to the UI than the scenario-based ones. In theory, I could write my own UI app, but I literally just asked how to make a button do stuff, so clearly I'm no expert.

    Any help is appreciated.
     
    #1 Occam's Razer, Sep 23, 2016
    Last edited: Sep 23, 2016
    • Like Like x 2
  2. Occam's Razer

    Occam's Razer
    Expand Collapse

    Joined:
    Aug 7, 2013
    Messages:
    1,152
    Okay, so, I figured some of this out. I dove back into the core .lua files and managed to find code to send messages to the messages app. What I found pretty much entirely answers most of my questions on the display/UI front, so we're good there. The only slight concern might be interruptions from vehicle damage updates, but from a game design standpoint it would probably be best not to have ongoing conversations while the player is moving. Though that does give me an idea for a texting-while-driving simulation.

    Still, that leaves input. In a move of desperation, I've installed custom 'answer' inputs on the SBR4, the vehicle that is being used in my proof-of-concept file. Not ideal, since they're vehicle specific and will remain active inputs for as long as the mod is installed, but for at least demonstrative purposes, it'll do. Currently, I have a conversation that can be navigated based on the state of the lights:

    Code:
    answerOne = be:getPlayerVehicle(0):queueLuaCommand("obj:queueGameEngineLua('ansIn_1 = ('..electrics.values['lights']..')')")
    ...but whenever I try to use my custom inputs, I get an error.

    Code:
    answerOne = be:getPlayerVehicle(0):queueLuaCommand("obj:queueGameEngineLua('ansIn_1 = ('..electrics.values['answerOne']..')')")
    Both lines are in onRaceTick. I've double checked the input names, they're solid, and the input is listed under electrics inside the input_actions file. The error on the console reads:

    Code:
    FATAL LUA ERROR: [string "string"]:1: attempt to concatenate field 'answerOne' (a nil value)
    I can confirm that the custom inputs are working at least in theory: the vehicle-specific bindings app displays all three as working properly.
     
  3. stenyak

    stenyak
    Expand Collapse
    Programmer & Global Moderator
    BeamNG Team

    Joined:
    Aug 6, 2012
    Messages:
    1,901
    I'm not sure what's the goal here. The queue* functions are queuing a string for later execution in a different thread.

    This means you will not get a return value, since the code is not actually being executed right there and then; instead it's enqueued fro later execution, which may be as soon as 1 microsecond later, or up to many milliseconds later.

    Therefore, answerOne is always going to be nil, since queueLuaCommand cannot return anything.
     
  4. Occam's Razer

    Occam's Razer
    Expand Collapse

    Joined:
    Aug 7, 2013
    Messages:
    1,152
    Wow, I kinda forgot a bit about this thread.
    It's not ideal, but I was just trying to find some way for a player input to be registered by a scenario's .lua file. I do have it working (using the turn signals and emergency lights as inputs... so, not ideal). Through all of the game files, wiki, and forums this is the only snippet of code* that seems to be designed to get information from an input to a scenario lua file, albeit indirectly. So, I used that. Biggest issue is that doesn't accept vehicle-specific inputs, even on official vehicles, so I'm still tentatively looking for answers.

    *Well, as of the last version. I haven't checked everything in the new campaigns.
     
  5. stenyak

    stenyak
    Expand Collapse
    Programmer & Global Moderator
    BeamNG Team

    Joined:
    Aug 6, 2012
    Messages:
    1,901
    You can do that, but answerOne is never going to get assigned any meaningful value.
    What you probably want to use instead is "ansIn_1", which you instructed to hold a value (after those enqueued commands are executed in the near future).
     
    #5 stenyak, Oct 7, 2016
    Last edited: Oct 7, 2016
  6. Occam's Razer

    Occam's Razer
    Expand Collapse

    Joined:
    Aug 7, 2013
    Messages:
    1,152
    Oh, you thought I was using the inputs directly in an 'if' statement. I was actually already using the 'ans' values:

    Code:
    if ansIn_1 == 1 then
    'answerOne' was just the name of the custom input that I had added to the test vehicle. Unless that wasn't what you'd meant. In any case, I've uploaded my .lua file to forgo any further confusion. I've since deleted the custom input_actions file, however. Multiple commented-out lines consist of the various failed attempts at getting satisfactory results, to include my custom vehicle-specific input, an official vehicle-specific input, and the lightbar input (which worked, but upon the lightbar's being turned off, the electrics value started climbing for some reason).
     

    Attached Files:

  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