PDA

View Full Version : inputtext problem


Lirbo
17/05/2014, 07:19 PM
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:
if(inputtext > DOF2_GetInt(pFile(playerid),"Money")){SendClientMessage(playerid,COLOR_DENIED,"[ERROR] {FF6969}You don't have this ammount of money"); return 1;}

Stinged
17/05/2014, 07:53 PM
inputtext is a string.
Use isnumeric(string) to check if it's a number.
If it was, use strval(inputtext) > ... instead of inputtext.

Lirbo
17/05/2014, 08:00 PM
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?

awsomedude
17/05/2014, 08:08 PM
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;
}

Patrick
17/05/2014, 08:10 PM
Use strval to convert a string into a integer.

for example

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

Stinged
17/05/2014, 08:53 PM
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:
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);
}