SA-MP Forums Archive
inputtext problem - 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)
+--- Thread: inputtext problem (/showthread.php?tid=513722)



inputtext problem - Lirbo - 17.05.2014

pawn Код:
if(dialogid == 4){
    if(inputtext > DOF2_GetInt(pFile(playerid),"Money")){SendClientMessage(playerid,COLOR_DENIED,"[ERROR] {FF6969}You don't have this ammount of money"); return 1;}
    DOF2_SetString(pFile(playerid),"Bank",inputtext); DOF2_SetString(pFile(playerid),"Money",-inputtext);}
    return 1;}
problem: array must be indexed (variable "inputtext")

the error line:
pawn Код:
if(inputtext > DOF2_GetInt(pFile(playerid),"Money")){SendClientMessage(playerid,COLOR_DENIED,"[ERROR] {FF6969}You don't have this ammount of money"); return 1;}



Re: inputtext problem - Stinged - 17.05.2014

inputtext is a string.
Use isnumeric(string) to check if it's a number.
If it was, use strval(inputtext) > ... instead of inputtext.


Re: inputtext problem - Lirbo - 17.05.2014

Quote:
Originally Posted by Stinged
Посмотреть сообщение
inputtext is a string.
Use isnumeric(string) to check if it's a number.
If it was, use strval(inputtext) > ... instead of inputtext.
Example please?


Re: inputtext problem - awsomedude - 17.05.2014

pawn Код:
if(IsNumeric(inputtext) > DOF2_GetInt(pFile(playerid),"Money")) return SendClientMessage(playerid,COLOR_DENIED,"[ERROR] {FF6969}You don't have this ammount of money");

stock IsNumeric(string[])
{
    for (new i = 0, j = strlen(string); i < j; i++)
    {
        if (string[i] > '9' || string[i] < '0') return 0;
    }
    return 1;
}



Re: inputtext problem - Patrick - 17.05.2014

Use strval to convert a string into a integer.

for example
pawn Код:
if(strval(inputtext) > DOF2_GetInt(pFile(playerid),"Money")) return SendClientMessage(playerid,COLOR_DENIED,"[ERROR] {FF6969}You don't have this ammount of money");



Re: inputtext problem - Stinged - 17.05.2014

Yes just like I said.
I just added that you should use IsNumeric to make sure the player entered an integer.
Get the IsNumeric stock from awesomedude's post and do this:
pawn Код:
if(IsNumeric(inputtext)
{
    if(strval(inputtext) > DOF2_GetInt(pFile(playerid),"Money")) return SendClientMessage(playerid,COLOR_DENIED,"[ERROR] {FF6969}You don't have this ammount of money");
}
else
{
    SendClientMessage(playerid, YOURCOLOR, MESSAGE THAT HE HAS TO ENTER A NUMBER);
}