|
sudin Beginner
Joined: 25 Feb 2008 Posts: 13
|
Posted: Fri Feb 29, 2008 2:06 pm
how do i distinguate a number from a string (a word) ? |
Hi
I would like to know if the paramater is a number or a string.
so if (parameter is a number) {do something} else [parameter is a word] {do something else}
for example :
get object (here it is a word : it will get the object)
get 4 (here it is a shortcut : get 4 coins)
get 4 object (get 4 times the object)
Thanks, sudin |
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Fri Feb 29, 2008 2:44 pm |
You are looking for #IF and %number.
Paste the text in the code box into the command line and hit enter.
Code: |
#alias test {#if (%number(%1) or %1==0) {#show The object is a number it is %1} {#show The object is a word and it is %1}} |
So to see if four is a word or a number you would type, "test four" without the quotes.
To test to see if 4 is a number you would type, "test 4".
Here are the results.
test four
The object is a word and it is four
test 4
The object is a number it is 4 |
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
sudin Beginner
Joined: 25 Feb 2008 Posts: 13
|
Posted: Fri Feb 29, 2008 3:08 pm |
Exactly what i wanted :) it works well. Thanks
|
|
|
|
Leitia Adept
Joined: 04 May 2007 Posts: 292 Location: Boston
|
Posted: Sun Mar 02, 2008 10:05 am |
%number is also good to use in math or printing if you are unsure if you will have a number. I have ended up with numbers that looked like 2000 * 300 * 4000 because I tried to evaluate a null string. Format will not print if you use a number string and do not provide a number, also having a zero to represent not having a variable is easier to look at in statistics, as #sh I have %number(@curbrews) brews in curbrews, where curbrews was an #unvar that would be blank.
|
|
|
|
|
|