0

我有一个功能,允许我在一行中添加和删除字符,我想将其限制为大约 10 个字符

function love.keypressed(key, unicode)
    if key == "backspace" or key == "delete" then
        player = string.sub(player, 1, #player-1)
    elseif unicode > 31 and unicode < 127 then
        player = player .. string.char(unicode)
    end
end
4

1 回答 1

1

如果字符串太长,您能否通过不添加到字符串来限制长度?还是你追求别的?

function love.keypressed(key, unicode)
    if key == "backspace" or key == "delete" then
        player = string.sub(player, 1, #player-1)
    elseif unicode > 31 and unicode < 127 and #player <=10 then
        player = player .. string.char(unicode)
    end
end
于 2014-02-28T17:29:31.560 回答