![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | plambrecht |
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.
Can’t you convert the string into an integer and clamp it using clamp(value, min, max)
? I think it should work.
Bubu | 2021-04-16 14:11