The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+1 vote

how can i do this with this code

var normal_char = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0"]

func _on_LineEdit_text_entered(new_text):
    if new_text != "":if !new_text in FS.level_names:
        level_name = new_text
        level_path = "res://saves/scene_saves/"+str(level_name)
        $Label.text = level_name
        $Label.visible = true
        can_play = true
        FS.level_names += [level_name]

when i use

if !new_text.find(normal_char) <=0:

it dont work

in Engine by (99 points)


it prints:


[a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0]


but when i use


it prints correctly

1 Answer

+1 vote
Best answer

Try a for loop

for _char in new_text:
    if _char not in normal_char:
        return #exit the _on_LineEdit_text_entered func

where the return is in the code you can replace with a function to notify of invalid entry for example

$LineEdit.set_placeholder("Please enter valid text")

Strings also have a is_valid_identifier func

if new_text.is_valid_identifier:
    if !new_text.has("_"):
by (6,942 points)
selected by

Thank you!!!

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.