[SOLVED] Backspace and enter input doesn't work for deleting and modifying text in label

I don’t know why but typing input works, but backspace and enter doesn’t do anything. The label doesn’t get deleted.

image

function on_input(self, action_id, action)
    if action_id == hash("type") then
        msg.post("/computer_sound#computer-sound", "play_keyboard")
        self.message = self.message .. action.text
        label.set_text("#code_input_box", self.message)
    elseif action_id == hash("backspace") and action.repeated then
        msg.post("/computer_sound#computer-sound", "play_keyboard")
        local l = string.len(self.message)
        self.message = string.sub(self.message, 0, l-1) 
        label.set_text("#code_input_box", self.message) 
    elseif action_id==hash("enter") then
        msg.post("/computer_sound#computer-sound", "play_keyboard")
        if self.message == actual_book_code then
            msg.post("/minigame_go#insert-book_code", "delete_book")
        end
    end
end

You have to add Key Triggers for enter and backspace:

4 Likes

Thank you, sorry, that’s amateur of me, I’m pretty new to Defold. :sweat_smile:

1 Like

You’re welcome. Not a problem at all. We all been there :smiley:
Also I saw that the example is missing this part. Maybe @britzl can fix it when he got free time:

1 Like

Yea I was looking at that and trying to replicate it. Hahahha.

I’ll make a note of it. But perhaps someone can beat me to it and provide a PR with an updated image showing both text and key input:

1 Like

done

2 Likes