You activate an NPC. A special NPC screen pops up. The NPC says hello. But you reply not by clicking on dialog options or stuff like that, but by directly typing in your greeting. After that you just use the sucker like a chat bot, which recognizes certain words and reacts to them. For example you might type in "Let us trade", and a shop interface pops up. Or, if the NPC is not a merchant, he tells you so and directs you to the closest store. But how do you get love to recognize text? I've used this code:
Code: Select all
local utf8 = require("utf8")
function love.textinput(t)
if npcchat == "on" then
yourphrase = yourphrase .. t
function love.update(dt)
if kb.isDown('backspace') and npcchat == true then
local byteoffset = utf8.offset(yourphrase, -1)
if byteoffset and npcchat == true then
yourphrase = string.sub(yourphrase, 1, byteoffset - 1)
end
end
function love.keypressed(key)
if kb.isDown("return") and npcchat == true then
npcchat = "off"
InterpretingWhatYouTyped = "on"
end