I am using a LineEdit node for a numerical input (have that figured out), but also need to restrict how high or low the number is. If they enter a number above the range, it should display the highest number possible, if lower, then the opposite. Kind of like what "clamp" does, but I can't seem to get clamp to work in my code.
I am using the following code:
extends LineEdit
var regex = RegEx.new()
var oldtext = ""
func _ready():
regex.compile("^[0-9]*$")
func _on_LineEdit_QTY_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))
Any help is greatly appreciated.