Text Input and Chat Box
Posted: Mon Jun 15, 2015 4:13 pm
I'm in the beginning stages of making a chat box for my TextBased RPG. I thought I'd get some ideas on how to accomplish this task. Right now my thinking is is put the user text in a variable "Player1['input']" then when user hits enter Game parses the sentence and feeds back an answer and empties the variable out. Right now I'm stuck on how to get the SHIFT/Spacebar and Punctuation to work correctly. This is what my function looks like so far. Before I go to far in building the chat function what are some tips from you guys to help me out. I'm pretty new to programming.
Also feel free to give me some tips in general, I'll take them.
Code: Select all
function love.keypressed( key, isrepeat )
if key == 'escape' then love.event.quit() end
if Settings['state'] == "PLAYING" and key and key:match( '^[%w%s]$' ) then Player1['input'] = Player1['input']..key end
if Settings['state'] == "PLAYING" and key == "backspace" then Player1['input'] = Player1['input']:sub(1, -2) end
end
Also feel free to give me some tips in general, I'll take them.