Listens to text input trigger "type" and modifies the game object label with the bunny's speech according to input. A "backspace" key trigger has also been added.
text.script
function init(self)
msg.post(".", "acquire_input_focus")
self.message = ""
end
function on_input(self, action_id, action)
if action_id == hash("type") then
self.message = self.message .. action.text
label.set_text("#label", self.message)
elseif action_id == hash("backspace") and action.repeated then
local l = string.len(self.message)
self.message = string.sub(self.message, 0, l-1)
label.set_text("#label", self.message)
end
end
on_input()
will be called whenever input is received.message
that stores the text.If you want to play with these examples, you can get the project on Github.
Do you want to see more examples? Why not write a few yourself and submit a pull request? We love contributions.