Keyboard input?

  • #1, z madeleine-vMonday, 04. July 2022, 15:23 hodinky 2 years ago
    Looked through the forum for help with this, but new to the code. I wanted to make a puzzle where you find a page number and the player will input it to find information they need in a book on that specific page. I know there's an input feature in Lua, but I can't find how to get it to work. I found this thread:

    But some of the script posted off-site seems to have been deleted unfortunately.

    Any help would be appreciated! Once I get more familiar with the key input, I'd like to have sequences where the player inserts key words into conversations with npcs as to lead to new dialogue, so I figured numeric 'passwords' would be the best way to start. Thanks!

    Bažant

    11 Posts


  • #2, z afrlmeMonday, 04. July 2022, 16:52 hodinky 2 years ago
     Here's a very basic key input example I shared to someone else on our discord server. It's a crude example,  but it should probably be enough for what you are wanting to do.

    Imperátor

    7285 Posts

  • #3, z madeleine-vWednesday, 06. July 2022, 03:01 hodinky 2 years ago
     Here's a very basic key input example I shared to someone else on our discord server. It's a crude example,  but it should probably be enough for what you are wanting to do.
    thanks! I'll play around with this 

    Bažant

    11 Posts

  • #4, z madeleine-vSunday, 17. July 2022, 19:03 hodinky 2 years ago
    i got it to work. and it's perfect for what I need. However, I'm a dummy - how do you have multiple 'txt-inputs'? Is this possible? The script I know can be changed from 'world' to anything, but if I wanted to have several different things for input, how would I accomplish this? Thank you

    Bažant

    11 Posts

  • #5, z afrlmeSunday, 17. July 2022, 22:14 hodinky 2 years ago
    Do you need a lot of different text inputs or is it just a few different ones?

    If it's just a few then you can edit the function & insert a few elseif queries into it, so it looks like something along the lines of this...
    function processTxt()
    
     if str.String == "world" then
    
       startAction(Actions["hello_world"]) -- true
    
     elseif str.String == "example text 1" then
    
       startAction(Actions["example1"]) -- true
    
     elseif str.String == "example text 2" then
    
      startAction(Actions["example2"]) -- true
    
     else
    
       startAction(Actions["invalid_input"]) -- false
    
     end
    
    end

    For a lot of text inputs a table/array would be a better approach, but arrays can get a bit complicated as you will most likely need to create sub-arrays or keys to handle both data for the engine to read as well as instructions for the engine to parse.
    
    
    local t_answers = {
    
    {ans = "world", act = "hello_world"},
    
    {ans = "some text 1", act = "example1"},
    
    {ans = "some text 2", act = "example2"},
    
    {ans = "some text 3",  act = "example3"},
    
    {ans = "some text 4", act = "example4"},
    
    {ans = "some text 5",  act = "example5"}
    
    }
    
    
    
    function processTxt()
    
     for i = 1, #t_answers do
    
      if str.String == t_answers[i].ans then
    
       startAction(Actions[t_answers[i].act])
    
       break
    
      end
    
      -- + --
    
      if i == #t_answers and str.String ~= t_answers[#t_answers].ans then
    
       startAction(Actions["invalid_input"])
    
      end
    
     end
    
    end

    Imperátor

    7285 Posts

  • #6, z madeleine-vMonday, 18. July 2022, 19:48 hodinky 2 years ago
    Thank you! I was planning to have a good amount of different inputs for dialogue (Harvester game inspirations). However, I may change this instead via another means and just save inputs for password-related puzzles if that's what you recommend.

    Bažant

    11 Posts

  • #7, z afrlmeWednesday, 20. July 2022, 12:46 hodinky 2 years ago
    That's up to you, but text adventure games are a lot of work if you want flexible inputs to work instead of the engine requiring a very specific input/phrase. The script I provided you with is very very simple compared the one I wrote for a text adventure game (I haven't shared that one yet) & because it's so simple you can only listen out for specific input/phrases instead of being able to pull keywords out of the text which would allow you to potentially build a specific input/phrase regardless of what the player types into the text input field.

    Anyway, you can always use the regular dialog system & update conditions/values depending on which dialog options the player selects. You can also control which dialog options will be available by controlling them via values too. I'm just going to assume you have some kind of npc dating feature thing in mind, seeing as you mentioned the harvester type games.


    Imperátor

    7285 Posts

  • #8, z madeleine-vThursday, 21. July 2022, 04:44 hodinky 2 years ago
    No dating (although that would be cute). My idea originally was for the player to see something in a scene and then intuit that they'll bring that up with a character to get more information from them. Instead, I'll spare myself the extra stress and take your advice.  Thank you, afrlme smile

    Bažant

    11 Posts