MAXScript FAQ > MAXScript Values > How do I check if a string contains only numbers? |
I like to check whether the text of an edit text UI element contains numbers or letters.
If it contains numbers, I like it to return the number.
But if it contains letters, I want it to display a message "You may only type numbers, try again"
This simple script implements a kind of "micro-listener". It uses the Execute method to turn the string typed in the edit text field into a MAXScript expression. It lets you not only enter numbers, but also constants like Pi, or global variables that you have defined. Not only this, you can define global variables inside the script, and even create objects on the fly!
125.1 is a valid expression - it is a constant and evaluates to itself (125.1).
On the other hand, d returns undefined as it is undefined.
Surprisingly, e does not return undefined - it is a reserved keyword in MAXScript!
Same with pi -as expected, it returns 3.14149....
Trying to add two undefined values results in an invalid expression.
This variable is also undefined...
...Until we define it! Now it is equal to 10...
...And so we can write an expression containing constants and variables!
Typing in a function name, in this case the constructor of a box, we get the function back.
By calling the function, we can create objects just like in the "real" Listener!
This box will be created 100 units to the right because we specified the position...