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 に答える