SA-MP Forums Archive
error 033: array must be indexed (variable "arrVehInfo") - 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: error 033: array must be indexed (variable "arrVehInfo") (/showthread.php?tid=631635)



error 033: array must be indexed (variable "arrVehInfo") - sscarface - 02.04.2017

PHP код:
new arrVehInfo[][][] =
{
      {
41156000"Infernus"},
      {
54112000"Bullet"}
}; 
PHP код:
public OnPlayerStateChange(playeridnewstateoldstate)
{
    
// Was he onfoot and THEN he entered the driver and if yes, then only show him the info!
    
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
    {
        new 
iVeh GetPlayerVehicleID(playerid); // Get his vehicle ID not vehicle MODEL.
        
new iVehModel GetVehicleModel(iVeh); // Can call implicitly the above 2 functions, but multiple calls, no - no or just for simplicity's sake
        
for(new index 0index sizeof(arrVehInfo); index++ )
        {
             if(
arrVehInfo[index][0] == iVehModel)
             
// Yes - he's in that row's model
             
{
                  new 
szString[80];
                  
format(szStringsizeof szString"VEHICLE: You can sell this %s at a nearby carshop for $%d."arrVehInfo[index][2], arrVehInfo[index][1] ) ;
                  
// remember - the 0th pos was the model, 1st pos - the price and the 2nd pos - the string.
                  
SendClientMessage(playerid, -1szString);
                  break ; 
// You got the vehicle, why loop anymore?
             
}
        }
        return 
1;
    } 
ERROR:

PHP код:
(16268) : error 033: array must be indexed (variable "arrVehInfo")
Pawn compiler 3.2.3664              Copyright (c1997-2006ITB CompuPhase
1 Error




Re: error 033: array must be indexed (variable "arrVehInfo") - Flamehaze7 - 02.04.2017

Код:
if(arrVehInfo[index][0]
This is just a two dimensional array but when you created it it was a 3Dimensional Array


Re: error 033: array must be indexed (variable "arrVehInfo") - sscarface - 02.04.2017

Could you please explain me more with coding?


Re: error 033: array must be indexed (variable "arrVehInfo") - coool - 02.04.2017

he means the last bracket:
Quote:

new arrVehInfo[][][] =
{
{411, 56000, "Infernus"},
{541, 12000, "Bullet"}
};

It isn't needed.


Re: error 033: array must be indexed (variable "arrVehInfo") - jlalt - 02.04.2017

you may try this:
PHP код:
if(arrVehInfo[index][0][0] == iVehModel
PHP код:
public OnPlayerStateChange(playeridnewstateoldstate

    
// Was he onfoot and THEN he entered the driver and if yes, then only show him the info! 
    
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER
    { 
        new 
iVeh GetPlayerVehicleID(playerid); // Get his vehicle ID not vehicle MODEL. 
        
new iVehModel GetVehicleModel(iVeh); // Can call implicitly the above 2 functions, but multiple calls, no - no or just for simplicity's sake 
        
for(new index 0index sizeof(arrVehInfo); index++ ) 
        { 
             if(
arrVehInfo[index][0][0] == iVehModel
             
// Yes - he's in that row's model 
             

                  new 
szString[80]; 
                  
format(szStringsizeof szString"VEHICLE: You can sell this %s at a nearby carshop for $%d."arrVehInfo[index][2], arrVehInfo[index][1] ) ; 
                  
// remember - the 0th pos was the model, 1st pos - the price and the 2nd pos - the string. 
                  
SendClientMessage(playerid, -1szString); 
                  break ; 
// You got the vehicle, why loop anymore? 
             

        } 
        return 
1
    } 



Re: error 033: array must be indexed (variable "arrVehInfo") - sscarface - 02.04.2017

Quote:
Originally Posted by jlalt
Посмотреть сообщение
you may try this:
PHP код:
if(arrVehInfo[index][0][0] == iVehModel
PHP код:
public OnPlayerStateChange(playeridnewstateoldstate

    
// Was he onfoot and THEN he entered the driver and if yes, then only show him the info! 
    
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER
    { 
        new 
iVeh GetPlayerVehicleID(playerid); // Get his vehicle ID not vehicle MODEL. 
        
new iVehModel GetVehicleModel(iVeh); // Can call implicitly the above 2 functions, but multiple calls, no - no or just for simplicity's sake 
        
for(new index 0index sizeof(arrVehInfo); index++ ) 
        { 
             if(
arrVehInfo[index][0][0] == iVehModel
             
// Yes - he's in that row's model 
             

                  new 
szString[80]; 
                  
format(szStringsizeof szString"VEHICLE: You can sell this %s at a nearby carshop for $%d."arrVehInfo[index][2], arrVehInfo[index][1] ) ; 
                  
// remember - the 0th pos was the model, 1st pos - the price and the 2nd pos - the string. 
                  
SendClientMessage(playerid, -1szString); 
                  break ; 
// You got the vehicle, why loop anymore? 
             

        } 
        return 
1
    } 
Thanks