First of all make sure the method is actually triggered. The text_entered
signal is emitted once the user presses Enter on the LineEdit. Is that what you want?
For clarity, you could keep NT as an integer throughout the code:
if new_text.is_valid_integer():
NT = int(new_text)
for i in GridSize_Range:
if NT == i:
GridGenerator_Script.ValidGridSize = true
break; # No need to keep running the loop
self.clear()
else:
GridGenerator_Script.ValidGridSize = false
self.clear()
In fact if this is all the code, you could further simplify it to:
if new_text.is_valid_integer():
NT = int(new_text)
GridGenerator_Script.ValidGridSize = NT in GridSize_Range
else:
GridGenerator_Script.ValidGridSize = false
self.clear()
This also sets ValidGridSize to false is NT is not within the range. I am not sure if this is your intended behavior or not. You can even go further and turn it into a one-liner:
GridGenerator_Script.ValidGridSize = new_text.is_valid_integer() and int(new_text) in GridSize_Range
In any case it sounds like you are attempting to have a number input box with a limited range of values. Perhaps a SpinBox node would be more appropriate than a LineEdit in this case?