• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
  • Minecraft 1.16.220 Update + Bug/Crash Fixes
    Added MCPE 1.16.220 version and fixed crashes for multiple plugins. You can view the full changelist here.
  • Forum Updates - 4/11/2021
    Various changes have been made to the forums and a few categories. You can view the full changelist here.

A tutorial showing how to check if a variable is a number or not

Warning!
Hello , there have been no replies in this thread for more than 30 days.
Please make sure you have a valid reason before you reply to this thread or you may face moderation action.
#1
With this code, you are able to check if a variable is a number or not, once you paste this code to a command, do /<cmd> 12345 then it will say "12345 is a number", but if you do /<cmd> test123 then it will say "test123 is not a number."
Code:
1. %var% = \"\" + %args%[1] + \"\"
2. %num% = 0
3. %text% = %var%
4. %numbers% = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
5. if %num% >= size(%var%) then goto 12
6. %letter% = substring(%text%, (size(%text%) - 1), size(%text%))
7. %text% = substring(%text%, 0, (size(%text%) - 1))
8. if varset(%numbers%[%letter%]) = %false% then %isnum% = %false%
9. if varset(%isnum%) = %false% then %isnum% = %true%
10. %num% = %num% + 1
11. goto 5
12. if varset(%isnum%) = %false% then message %p% Please make sure to put a valid number.
13. if varset(%isnum%) = %false% then exit
14. if %isnum% = %true% then message %p% %var% is a number.
15. if %isnum% = %true% then exit
16. message %p% %var% is not a number.
if you replace line 1 to
Code:
1. %var% = 12345
then it wont work, it will say that it isn't a number, so make sure to replace it to
Code:
1. %var% = \"\" + 12345 + \"\"