Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

less specific inputs (terminal text game)

edited January 2017 in Questions Posts: 38

I am making text game (ever heard of "Zork" or "Adventure", like those) and I am trying to make it so that the players inputs don't have to be so specific. I have already made it so that the inputs aren't case-sensitive but I need to take it a step father. I want to make it so that multiple phrases that mean the same thing can give the same result. I tried using an "OR" argument in my "IF" statements but for some reason that isn't working. I thought I could also try making a variable and assigning all the same meaning inputs to it but is that possible or is there a better way? I also thought I could remove certain characters from the input like a "?", ".", "'" or "," or extra spaces before the input is processed instead of adding the same phrase just with an "?" or "." to the list of same meaning phrases, but how would I do that? And I also want to make it so for certain questions like "Where would you like to go?" it would detect if your input just had the keyword, like in "I would like to go to the desert" it would just detect "desert" and make that your answer. Here's the code but keep in mind I plan on fixing the bug where if the reply or your input gets to big they disappear, just turn on the Espeak perimeter and read in the output box if you have to.

Edit: For some reason it didn't paste right but it's fixed now. Nvm I think it just limits the amount of characters can be in the post. I'll just coment the code tus_emoji="

Comments

  • dave1707dave1707 Mod
    Posts: 7,612

    @GameCoder It doesn't look like all of your code is showing.

  • I think it's the emoji I used wasn't a part of the Unicode used on this website so it cut it off. I'll just remove all the emojis in my code and hopefully it will be fixed.

  • Code:


    --# Main -- Text game -- Use this function to perform your initial setup function setup() print("Wellcome to text game!") --Status status="non-existent" status_emoji="?" --Settings parameter.boolean("Espeak", false, function(b) print("Espeak has been toggled to "..tostring(b)) end ) interactive_world="menu" input="" reply="" question="none" showKeyboard() end -- This function gets called once every frame function draw() -- This sets a dark background color background(40, 40, 50) ---------------- Draw Status ------------------ fill(180, 180, 180, 255) font("Inconsolata") fontSize(25) text("status:"..status,WIDTH/2, HEIGHT-20) fontSize(35) text(status_emoji,WIDTH/2, HEIGHT-50) ----------------------------------------------- -- input -- fontSize(30) fill(165, 165, 165, 255) text(input,WIDTH/2,HEIGHT/2+30) -- reply -- fontSize(40) fill(93, 188, 19, 255) text(reply,WIDTH/2,HEIGHT/2+60) end function keyboard(key) if key == RETURN then print(input) input=string.lower(input) output() input="" elseif key == BACKSPACE then input = string.sub(input, 1, -2) else input = input .. key end end function output() if interactive_world=="menu" then if question=="none" then if input=="hello" then reply="Greetings" elseif input=="bye" then reply="How can you leave without a physical body?" elseif input=="help" then reply="How can I assist you? Would you like to start an adventure?" question="help" elseif input=="who am i" then reply="Nobody, at the moment" elseif input=="could i go on an adventure" then reply="Absolutely, where would you like to go?" question="adventure" else reply="invalid" end elseif question=="adventure" then if input=="desert" then interactive_world="Desert" reply="You are now riding a motorcycle across a long dry desert road, suddenly it breaks down forcing you to an immediate stop" status="Unhappy" status_emoji="" elseif input=="tundra" then interactive_world="Tundra" reply="You are now enjoying a flight to vacation. Your plane is crossing over very freezing terrain when suddenly everything around you starts shaking for a bit. The intercom comes on shortly afterwards saying... I got tired of writing these, I'll finish this later" status="Worried" status_emoji="" elseif input=="savanna" then interactive_world="Savanna" reply="You are on an hot air balloon observing the vast wildlife of this savanna with your guide... I got tired of writing these, I'll finish this later" status="Shocked" status_emoji="" else reply="invalid answer, please choose either savanna, tundra or desert" question="adventure" end elseif question=="help" then if input=="yes" then reply="Where would you like to go?" question="adventure" elseif input=="no" then reply="What else can you do?" question="none" else reply="invalid answer, please say Yes or No" end end elseif interactive_world=="Savanna" then elseif interactive_world=="Tundra" then elseif interactive_world=="Desert" then end print(reply) if Espeak== true then speech.say(reply) end end function touched(touch) if touch.tapCount == 1 and touch.state == ENDED then showKeyboard() end end
  • Yep. there was no character cap, it was just the emoji that cut everything off.

  • dave1707dave1707 Mod
    Posts: 7,612

    @GameCoder Does your game have specific questions. If it does, then you could create a table of keywords for each question. Then you could compare the keywords for that question and see if any of them appear in the response.

  • edited January 2017 Posts: 38

    So words like "yeah" "yes" "affirmative" etc. could be put into a table for yes phases. But what if I just want to make it detect the word "dessert" in "I want to go on the dessert adventure" and automatically assume the player means I want to go to the dessert just because "dessert" was in the response when it asked "Where would you like to go".

  • edited January 2017 Posts: 38

    We might have to wait till tomorrow to figure this out. My iPad is almost dead and it is 10:15 where I live (eastern time). So I'm about ready to hit the hay. Thanks, I'll reply to you tomorrow (hopefully).

  • dave1707dave1707 Mod
    Posts: 7,612

    @GameCoder Unless you want to teach your device grammar, you're going to have a lot of limitations. Let's say your question is "Where would you like to go?" and in your table for that question you have dessert, Richmond, and Virginia. If they respond "How about going to the dessert" or "The dessert sounds nice", you would scan the response with the 3 words in the table and dessert would be found. You would then know that dessert was the answer. That would be an easy find. But if the response was "Anywhere in Virginia, but not Richmond", then you would have a problem because you would find 2 answers. One would be where they wanted to go and the other where they didn't want to go. You can see that open responses are going to be hard to determine what they really want.

Sign In or Register to comment.