Skip to content

Instantly share code, notes, and snippets.

@MarianoGnu
Created July 17, 2016 01:39
Show Gist options
  • Save MarianoGnu/11a14681654decf8543543a1e57ca955 to your computer and use it in GitHub Desktop.
Save MarianoGnu/11a14681654decf8543543a1e57ca955 to your computer and use it in GitHub Desktop.
extends LineEdit
var updating = false
const allowed = ["0","1","2","3","4","5","6","7","8","9"]
func _ready():
connect("text_changed",self,"otc")
func otc(text):
if updating: return
var pos = get_cursor_pos()
var n_text = ""
for i in range(text.length()):
if text[i] in allowed:
n_text += text[i]
else:
pos -=1
updating = true
set_text(n_text)
set_cursor_pos(pos)
updating = false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment