error 033: array must be indexed (variable "-unknown-")
#1

I'm having trouble figuring out how to use inputtext for a dialog based MDC. I got the code to work using a regular command and SendClientMessage, but I'm trying to move it to dialogs. Now, here's the code:

PHP код:
if(dialogid == DIALOG_POLICE_MDC)
    {
        if(!
response)
        {
            return 
1;
        }
        if(
response)
        {
            switch(
listitem)
            {
                case 
0:
                {
                    
ShowPlayerDialog(playeridDIALOG_POLICE_NAMESEARCHDIALOG_STYLE_INPUT"{FFFFFF}MDC - Name Search""{FFFFFF}Enter the name of the suspect:""Search""Back");
                }
                case 
1:
                {
                    
ShowPlayerDialog(playeridDIALOG_POLICE_PLATESEARCHDIALOG_STYLE_INPUT"{FFFFFF}MDC - Plate Search""{FFFFFF}Enter the plate of the vehicle:""Search""Back");
                }
                case 
3:
                {
                    
SendClientMessage(playeridCOLOR_LIGHTRED"ERROR: Coming soon!");
                }
            }
            return 
1;
        }
    }
    if(
dialogid == DIALOG_POLICE_NAMESEARCH)
    {
        if(!
response)
        {
            
ShowPlayerDialog(playeridDIALOG_POLICE_MDCDIALOG_STYLE_LIST"        ____[MDC - Mobile Data Computer]___""{FFFFFF}Name Search\n{FFFFFF}Plate Search\n{FFFFFF}BOLOs\n""Select""Cancel");
        }
        if(
response)
        {
            new 
string[128];
            new 
criminal inputtext;
            new 
Float:XFloat:YFloat:Z;
            
GetPlayerPos(criminalXYZ);
            
format(stringsizeof(string),"_______________________________[MDC - Mobile Data Computer]_______________________________");
            
SCM(playeridCOLOR_WHITEstring);
             
format(stringsizeof(string),"Full Name: "COL_WHITE"%s",  GetName(criminal));
            
SCM(playeridCOLOR_SJPDstring);
            
format(stringsizeof(string),"Full Name: "COL_WHITE"%s"PlayerInfo[criminal][pName]);
            
SCM(playeridCOLOR_SJPDstring);
              return 
1;
        }
    }
    if(
dialogid == DIALOG_POLICE_PLATESEARCH)
    {
        if(!
response)
        {
            
ShowPlayerDialog(playeridDIALOG_POLICE_MDCDIALOG_STYLE_LIST"        ____[MDC - Mobile Data Computer]___""{FFFFFF}Name Search\n{FFFFFF}Plate Search\n{FFFFFF}BOLOs\n""Select""Cancel");
        }
        if(
response)
        {
            new 
string[128];
            new 
plate inputtext;
            foreach(
Player,i)
            {
                if(
plate == PlayerInfo[i][pPlate1] || plate == PlayerInfo[i][pPlate2] || plate == PlayerInfo[i][pPlate3])
                {
                    
format(stringsizeof(string),"_______________________________[%d]_______________________________"plate);
                    
SCM(playeridCOLOR_WHITEstring);
                    
format(stringsizeof(string), "[Vehicle Owner:] "COL_WHITE"%s."PlayerInfo[i][pName]);
                    
SCM(playeridCOLOR_SJPDstring);
                } else return 
SCM(playeridCOLOR_LIGHTRED"There is no player with that license plate.");
            }
              return 
1;
        }
    } 
Errors:
PHP код:
C:\Users\Saint\Desktop\PRP\gamemodes\PRP.pwn(5131) : error 033: array must be indexed (variable "-unknown-")
C:\Users\Saint\Desktop\PRP\gamemodes\PRP.pwn(5153) : error 033: array must be indexed (variable "-unknown-"
Lines w/ Errors:
Код:
new criminal = inputtext;
Код:
new plate = inputtext;
Reply
#2

Код:
OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
As you can see inputtext is an array, a string to be more precise.
So you should do something like this.Instead of
Код:
new criminal = inputtext;
Use
Код:
if(sscanf(inputtext, "u", criminal))
      return SendClientMessage(playerid, COLOR, "Invalid player.");
I guess you're familiar with the sscanf function.
Reply
#3

Quote:
Originally Posted by Aly
Посмотреть сообщение
Код:
OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
As you can see inputtext is an array, a string to be more precise.
So you should do something like this.Instead of
Код:
new criminal = inputtext;
Use
Код:
if(sscanf(inputtext, "u", criminal))
      return SendClientMessage(playerid, COLOR, "Invalid player.");
I guess you're familiar with the sscanf function.
Ah, thank you. This fixed it. +rep'd.
Reply
#4

Quote:
Originally Posted by Aly
Посмотреть сообщение
Код:
OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
As you can see inputtext is an array, a string to be more precise.
So you should do something like this.Instead of
Код:
new criminal = inputtext;
Use
Код:
if(sscanf(inputtext, "u", criminal))
      return SendClientMessage(playerid, COLOR, "Invalid player.");
I guess you're familiar with the sscanf function.
Now I've come into another problem. It works now, no errors. But in-game, when I type in the criminal's name, it does nothing. Here's my code:
PHP код:
if(dialogid == DIALOG_POLICE_NAMESEARCH)
    {
        if(!
response)
        {
            
ShowPlayerDialog(playeridDIALOG_POLICE_MDCDIALOG_STYLE_LIST"        ____[MDC - Mobile Data Computer]___""{FFFFFF}Name Search\n{FFFFFF}Plate Search\n{FFFFFF}BOLOs\n""Select""Cancel");
        }
        if(
response)
        {
            new 
string[128];
            new 
criminal;
            new 
Float:XFloat:YFloat:Z;
            
GetPlayerPos(criminalXYZ);
            if(
sscanf(inputtext"u"criminal))
            {
                
format(stringsizeof(string),"_______________________________[MDC - Mobile Data Computer]_______________________________");
                
SCM(playeridCOLOR_WHITEstring);
                 
format(stringsizeof(string),"Full Name: "COL_WHITE"%s",  GetName(criminal));
                
SCM(playeridCOLOR_SJPDstring);
                
format(stringsizeof(string),"Full Name: "COL_WHITE"%s"PlayerInfo[criminal][pName]);
                
SCM(playeridCOLOR_SJPDstring);
                  return 
1;
            }
        }
    } 
Same thing with plates:
PHP код:
if(dialogid == DIALOG_POLICE_PLATESEARCH)
    {
        if(!
response)
        {
            
ShowPlayerDialog(playeridDIALOG_POLICE_MDCDIALOG_STYLE_LIST"[MDC - Mobile Data Computer]""{FFFFFF}Name Search\n{FFFFFF}Plate Search\n{FFFFFF}BOLOs\n""Select""Cancel");
        }
        if(
response)
        {
            new 
string[128];
            new 
plate;
            if(
sscanf(inputtext"d"plate))
            {
                foreach(
Player,i)
                {
                    if(
plate == PlayerInfo[i][pPlate1] || plate == PlayerInfo[i][pPlate2] || plate == PlayerInfo[i][pPlate3])
                    {
                        
format(stringsizeof(string),"_______________________________[%d]_______________________________"plate);
                        
SCM(playeridCOLOR_WHITEstring);
                        
format(stringsizeof(string), "[Vehicle Owner:] "COL_WHITE"%s."PlayerInfo[i][pName]);
                        
SCM(playeridCOLOR_SJPDstring);
                    } else return 
SCM(playeridCOLOR_LIGHTRED"There is no player with that license plate.");
                }
                  return 
1;
            }
        }
    } 
Reply
#5

Код:
if(!sscanf(...))
{
//do something
}
else
{
//error
}
The sscanf function returns 0 on succes.
Reply
#6

Quote:
Originally Posted by Aly
Посмотреть сообщение
Код:
if(!sscanf(...))
{
//do something
}
else
{
//error
}
The sscanf function returns 0 on succes.
Thank you. That fixed it.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)