IsNumeric Problem !! Fast help -
Toxik - 09.05.2015
Error
pawn Код:
C:\Users\CraTzy\Desktop\LVDM\gamemodes\LVDM.pwn(6262) : error 021: symbol already defined: "IsNumeric"
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase
1 Error.
The line of error
pawn Код:
stock IsNumeric(const string[])
{
new length = strlen(string);
if(!length) return false;
for(new i = 0; i < length; i++)
{
if(string[i] > '9' || string[i] <'0') return false;
}
return true;
}
This is my 2nd IsNumeric but idk how to put both on 1 Stock
pawn Код:
stock IsNumeric(const string[])
{
for(new i=0; string[i]; i++)
{
if(string[i] < '0' || string[i] > '9') return 0;
}
return 1;
}
+Rep who help me
NVM ~FIXED ~ by myself
pawn Код:
stock IsNumeric(const string[])
{
for(new i=0; string[i]; i++)
{
if(string[i] < '0' || string[i] > '9') return 0;
}
new length = strlen(string);
if(!length) return false;
for(new i = 0; i < length; i++)
{
if(string[i] > '9' || string[i] <'0') return false;
}
return true;
}
AW: IsNumeric Problem !! Fast help -
Mencent - 09.05.2015
Hello!
Either you rename the first function or you delete one of them.
Re: IsNumeric Problem !! Fast help -
ihatetn931 - 09.05.2015
You can't have 2 functions with the same name, You need to change the name on one of them.
I was to slow someone beat me to it
Re: IsNumeric Problem !! Fast help -
Sawalha - 09.05.2015
as the guy above me said, rename one of them or remove.
Re: IsNumeric Problem !! Fast help -
J4Rr3x - 09.05.2015
Delete both and use this
pawn Код:
IsNumeric(const string[])
{
for (new i = 0; i < strlen(string); i++)
if (string[i] > '9' || string[i] < '0') return 0;
return 1;
}
AW: IsNumeric Problem !! Fast help -
Mencent - 09.05.2015
Why you aren't write it like this?
PHP код:
stock IsNumeric(const string[])
{
new length = strlen(string);
if(!length)return 0;
for(new i;i<length;i++)
{
if(string[i] > '9' || string[i] < '0')return 0;
}
return 1;
}
Your fixed code won't be work. Take mine.
Re: IsNumeric Problem !! Fast help -
sammp - 09.05.2015
Okay, I really don't see the point in flipping the if statement around lol?!
Re: IsNumeric Problem !! Fast help -
SickAttack - 09.05.2015
Supports negative and positive numbers. It breaks the loop if false and then returns the state of the function's purpose afterwards.
pawn Код:
IsNumeric(const string[])
{
new length = strlen(string), bool:cancel = false;
if(!length) return false;
for(new i = 0; i < length; i ++)
{
if((i == 0) && string[0] == '-' || string[0] == '+') continue;
else if(string[i] > '9' || string[i] < '0')
{
cancel = true;
break;
}
}
if(cancel) return false;
return true;
}
Re: IsNumeric Problem !! Fast help -
Vince - 09.05.2015
Don't really see the need for those extensive functions. Your script will most probably use sscanf and in that case you can simply get away with:
pawn Код:
IsNumeric(const string[]) return !sscanf(string, "{d}");
Re: IsNumeric Problem !! Fast help -
sammp - 09.05.2015
Quote:
Originally Posted by SickAttack
Supports negative and positive numbers. It breaks the loop if false and then returns the state of the function's purpose afterwards.
|
if(string[i] > '9' || string[i] < '0') is the exact same as if(string[i] < '0' || string[i] > '9')
Same way that 8x5 is the same as 5x8
So both of his functions do the same thing but he just wasted time posting here