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.
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.
For something like this, I'd recommend using love.textinput(text). This function avoids anything you wouldn't want such as "backspace" or "escape" being typed in (even though you are excluding them). You'd not even need to worry about uppercase and punctuation since pressing shift + those keys work easily with love.textinput.
Thanks. I wish my code was half as nice as it looks. I have some awesome ideas for the storyline but its all about me deciding to finish a project for once.