SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 19/05/2017, 07:49 PM   #1
oSAINTo
Big Clucker
 
oSAINTo's Avatar
 
Join Date: Aug 2015
Posts: 174
Reputation: 24
Default error 033: array must be indexed (variable "-unknown-")

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 Code:
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 Code:
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:
Code:
new criminal = inputtext;
Code:
new plate = inputtext;
__________________

Sexy isn't she?
oSAINTo is offline   Reply With Quote
Old 19/05/2017, 07:55 PM   #2
Aly
Huge Clucker
 
Join Date: Oct 2012
Posts: 228
Reputation: 11
Default Re: error 033: array must be indexed (variable "-unknown-")

Code:
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
Code:
new criminal = inputtext;
Use
Code:
if(sscanf(inputtext, "u", criminal))
      return SendClientMessage(playerid, COLOR, "Invalid player.");
I guess you're familiar with the sscanf function.
Aly is offline   Reply With Quote
Old 19/05/2017, 07:59 PM   #3
oSAINTo
Big Clucker
 
oSAINTo's Avatar
 
Join Date: Aug 2015
Posts: 174
Reputation: 24
Default Re: error 033: array must be indexed (variable "-unknown-")

Quote:
Originally Posted by Aly View Post
Code:
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
Code:
new criminal = inputtext;
Use
Code:
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.
__________________

Sexy isn't she?
oSAINTo is offline   Reply With Quote
Old 19/05/2017, 08:04 PM   #4
oSAINTo
Big Clucker
 
oSAINTo's Avatar
 
Join Date: Aug 2015
Posts: 174
Reputation: 24
Default Re: error 033: array must be indexed (variable "-unknown-")

Quote:
Originally Posted by Aly View Post
Code:
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
Code:
new criminal = inputtext;
Use
Code:
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 Code:
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 Code:
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;
            }
        }
    } 
__________________

Sexy isn't she?
oSAINTo is offline   Reply With Quote
Old 19/05/2017, 08:07 PM   #5
Aly
Huge Clucker
 
Join Date: Oct 2012
Posts: 228
Reputation: 11
Default Re: error 033: array must be indexed (variable "-unknown-")

Code:
if(!sscanf(...))
{
//do something
}
else
{
//error
}
The sscanf function returns 0 on succes.
Aly is offline   Reply With Quote
Old 20/05/2017, 12:04 AM   #6
oSAINTo
Big Clucker
 
oSAINTo's Avatar
 
Join Date: Aug 2015
Posts: 174
Reputation: 24
Default Re: error 033: array must be indexed (variable "-unknown-")

Quote:
Originally Posted by Aly View Post
Code:
if(!sscanf(...))
{
//do something
}
else
{
//error
}
The sscanf function returns 0 on succes.
Thank you. That fixed it.
__________________

Sexy isn't she?
oSAINTo is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error 033: array must be indexed (variable "-unknown-") N0FeaR Scripting Help 1 03/05/2016 08:54 PM
[Ajuda] error 033: array must be indexed (variable "-unknown-") Hades12 Português/Portuguese 4 16/02/2015 05:01 PM
(230) : error 033: array must be indexed (variable "-unknown-") Ryan_Bowe Scripting Help 3 24/09/2013 09:59 PM
Got an error 033: array must be indexed (variable "-unknown-") BlackID Scripting Help 0 03/08/2012 06:38 AM


All times are GMT. The time now is 07:02 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.