我有一个功能,允许我添加和删除一行中的字符我希望将其限制为大约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
答案 0 :(得分: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