This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

(LineEdit use for nickname)
Interested in restrictions on the number and only Latin

p.s. sorry for my English: GoogleTranslate Edition

in Engine by (88 points)

What do you want to know? It's impossible to help you with this amount of information.

That the player could not enter more than 10 characters and that it was only Latin letters (use lineedit)

More precisely. It is necessary to count the number of сharacters entered and check whether the text entered contains only Latin characters.

1 Answer

+1 vote
Best answer

With latin characters you mean ã, ñ, õ, é, etc, right?
And you want to block the limit of characters to 10 or you can't type more than 10?

If you want to block up to 10 characters and the latin letters that you mentioned are the ones above, go to the node inspector and set the Max Length to 10.

To check if the text contains a latin letter, what you could do were link the LineEdit signal text_changed to its script and use the find() method to see if the text contains the letters that you want to check.

To be more pratical, I would suggest using a for loop, like this:

extends LineEdit

var latin_characters = ["ã", "ñ", "ó"] #Add all the characters that you want to look for

func _on_LineEdit_text_changed(new_text):
    for letter in latin_characters:
        if new_text.find(letter) > 0: #If it's not present, return -1
            print("Latin character %s found!"%letter)
by (519 points)
selected by

If you want to make sure it's ONLY latin characters, you could create another array with all the other characters and do the reverse logic, to make sure there are only the desired characters.

extends LineEdit

var latin_characters = ["ã", "ñ", "ó"] #Add all the characters that you want to look for
var normal_char = ["a", "b", "c"]

func _on_LineEdit_text_changed(new_text):
    var only_latin = true

    for normal in normal_char:
        if new_text.find(normal) >= 0:
            only_latin = false

    if only_latin:
        for letter in latin_characters:
            if new_text.find(letter) >= 0: #If it's not present, return -1
                print("Latin character %s found!"%letter)
    else:
        print("Only latin letters please!")

And to count the ammount of latin letters, the code would be this one, where amount is the amount of latin characters:

extends LineEdit

var latin_characters = ["ã", "ñ", "ó"] #Add all the characters that you want to look for
var normal_char = ["a", "b", "c"]

var amount = 0
var text_array = []

func _on_LineEdit_text_changed(new_text):
    var only_latin = true

    count_latin_letters()

    for normal in normal_char:
        if new_text.find(normal) >= 0:
            only_latin = false

    if only_latin:
        for letter in latin_characters:
            if new_text.find(letter) >= 0: #If it's not present, return -1
                print("Latin character %s found!"%letter)
    else:
        print("Only latin letters please!")

func count_latin_letters():
    text_array = []
    amount = 0

    for i in text:
        text_array.append(i)

    for letter in text_array:
        if letter in latin_characters:
            amount += 1

Your code helped me a lot, thanks! <3
p.s. I meant just "normal_char" (no latin), just wrote wrong

Glad I could help!
If you need help with something else, please ask!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.