Only words - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Only words (
/showthread.php?tid=156686)
Only words -
Dws - 23.06.2010
Hi guys, I'm making some commands using dialogs. I would like to know how to do a dialog(DIALOG_STYLE_INPUT) that only you can write words, not numbers.
Sorry for my English.
Re: Only words -
Hiddos - 23.06.2010
Search for the IsNumeric code which is somewhere on the forums. Immediately checking w/e a player types is impossible (Unfortunately)
Re: Only words -
Backwardsman97 - 23.06.2010
You could use the function IsNumeric or just make your own version. Here's the IsNumeric function.
pawn Код:
IsNumeric(const string[])
{
for (new i = 0, j = strlen(string); i < j; i++)
{
if (string[i] > '9' || string[i] < '0')
{
return 0;
}
}
return 1;
}
That's an older version. There may be a newer version out there. I'm not sure if this would return false if there was a string like "f2fs984hg2". If it did say that wasn't numeric then you could just use a loop to search the string for any number.
Re: Only words -
dice7 - 23.06.2010
Well of course it will return 0, if it finds a non numeric character
Re: Only words -
Dws - 23.06.2010
I use this function, but It returns true if I type something like e3cgf6.
Re: Only words -
dice7 - 23.06.2010
You are probably using it wrong. Show your code
Re: Only words -
(SF)Noobanatior - 23.06.2010
this is a better one
Код:
stock isNumeric(const string[]) {
new length=strlen(string);
if (length==0) return false;
for (new i = 0; i < length; i++) {
if (
(string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+') // Not a number,'+' or '-'
|| (string[i]=='-' && i!=0) // A '-' but not at first.
|| (string[i]=='+' && i!=0) // A '+' but not at first.
) return false;
}
if (length==1 && (string[0]=='-' || string[0]=='+')) return false;
return true;
}
Re: Only words -
dice7 - 23.06.2010
Your example has a lot of unneeded stuff.
Also, the 'ultimate' version would be this
pawn Код:
IsNumeric(const string[])
{
if (!strval(string))
{
for (new i = 0, j = strlen(string); i < j; i++)
{
if (string[i] != '0') return 0;
}
}
return 1;
}
pawn Код:
printf("%d\n", IsNumeric("0000")); //returns 1
printf("%d\n", IsNumeric("2341")); //returns 1
printf("%d\n", IsNumeric("+2341")); //returns 1
printf("%d\n", IsNumeric("-2341")); //returns 1
printf("%d\n", IsNumeric("jhb342u")); //returns 0
Re: Only words -
Dws - 23.06.2010
2 firsts doesn't work, I will try the last one.
Edit.: The last one doesn't work as I would like. If you type 3fdsl It returns 1, as I want, but if I type fasd3 It returns 0, at least it's something.
Thanks all.