Keyboard input?

  • #1, by madeleine-vMonday, 04. July, 15:23 A month 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!

    Newbie

    11 Posts


  • #2, by afrlmeMonday, 04. July, 16:52 A month 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.

    Imperator

    7158 Posts

  • #3, by madeleine-vWednesday, 06. July, 03:01 A month 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 

    Newbie

    11 Posts

  • #4, by madeleine-vSunday, 17. July, 19:03 A month 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

    Newbie

    11 Posts

  • #5, by afrlmeSunday, 17. July, 22:14 A month 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

    Imperator

    7158 Posts

  • #6, by madeleine-vMonday, 18. July, 19:48 3 weeks 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.

    Newbie

    11 Posts

  • #7, by afrlmeWednesday, 20. July, 12:46 3 weeks 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.


    Imperator

    7158 Posts

  • #8, by madeleine-vThursday, 21. July, 04:44 3 weeks 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

    Newbie

    11 Posts

Write post