Hi, for doing an integer field, you can modify the lineedit. Just add a LineEdit node to your scene, and attach this script to it:
GODOT 3.0.6
extends LineEdit
var regex = RegEx.new()
var oldtext = ""
func _ready():
regex.compile("^[0-9]*$")
func _on_LineEdit_text_changed(new_text):
if regex.search(new_text):
oldtext = new_text
else:
text = oldtext
set_cursor_position(text.length())
func get_value():
return(int(text))
BE SURE THAT YOU CONNECT LineEdit's signal text_changed
TO FUNCTION ON LineEdit _onLineEdit_text_changed
.
GODOT 3.1
extends LineEdit
var regex = RegEx.new()
var oldtext = ""
func _ready():
regex.compile("^[0-9]*$")
func _on_LineEdit_text_changed(new_text):
if regex.search(new_text):
text = new_text
oldtext = text
else:
text = oldtext
set_cursor_position(text.length())
func get_value():
return(int(text))
What i'm doing here, is first declaring a regular expresion that only accepts numeric input. When text changes, you check that the text is numeric. If so, you write that text, if not you keep old text. With get_value
function you can get the integer value.