Creating an array with variable's value index!
#1

I'm working on a command that spawn the player's chosen vehicle from the list, I use mSelection include to show this list. So, this is my code:
PHP код:
CMD:v(playeridparams[])
{
    if(
isnull(params)) System_Scm(playerid"Syntax: /v [get | engine | lights | hood | trunk | lock]"TYPE_GLOBAL);
    else
    {
        new 
            
vid GetPlayerVehicleID(playerid);
        if(!
strcmp(params"get"true))
        {
            new 
query[256],
                
rows;
            
mysql_format(MHandlequerysizeof(query), "SELECT * FROM `vehicles` WHERE `OwnerName` = '%s'"Character[playerid][Username]);
            
mysql_query(MHandlequery);
            
cache_get_row_count(rows);
            if(!
rows
            {
                
System_Scm(playerid"You need to own at least one vehicle."TYPE_ERROR);
            }
            else
            {
                new 
vehicles[rows], // line 24
                    
szModel// line 25
                
for(new 0rowsi++) // line 26
                
{
                    
cache_get_value_name_int(i"Model"szModel);
                    
vehicles[i] = szModel// line 28
                
}
                
ShowModelSelectionMenuEx(playeridvehiclessizeof(vehicles),"Your Vehicles"pVehiclesList);
            }
        }
    }
    return 
1;

But when I try to create an array 'vehicles' with 'rows' index, I got errors:
Quote:

./core/Commands.pwn(24) : warning 219: local variable "vehicles" shadows a variable at a preceding level
./core/Commands.pwn(24) : error 008: must be a constant expression; assumed zero
./core/Commands.pwn(24) : error 029: invalid expression, assumed zero
./core/Commands.pwn(25) : loose indentation
./core/Commands.pwn(25) : error 017: undefined symbol "szModel"
./core/Commands.pwn(26) : error 001: expected token: ";", but found "for"
./core/Commands.pwn(26) : loose indentation
./core/Commands.pwn(2 : error 017: undefined symbol "szModel"

Please help me solving these errors, thanks in advanced.
Reply
#2

You can't use dynamic size arrays in pawn (except with y_malloc). I'd suggest you create a limit on max user cars, like
pawn Код:
#define MAX_PLAYER_CARS 5
And use it instead of [rows]
Reply
#3

Quote:
Originally Posted by Misiur
Посмотреть сообщение
You can't use dynamic size arrays in pawn (except with y_malloc). I'd suggest you create a limit on max user cars, like
pawn Код:
#define MAX_PLAYER_CARS 5
And use it instead of [rows]
y_malloc seems hard to me so I decide to follow your way. I really appreciate your support!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)