calling enum with index
#1

Hi, I wanted to ask you a question.

Wanted to know if the enum have indices bone to not call them by how we declare it, but by a number.

Example:

pawn Код:
enum SI
{
    MaxPing, // INDEX 0
    MaxPacket, // INDEX 1
    MinFPS // INDEX 2
};
new ServerInfo[SI];

ServerInfo[0] = value;
now I tried to do so, but throws me the following errors:
pawn Код:
dir(863) : warning 213: tag mismatch
dir(863) : error 006: must be assigned to an array

This is my code:
pawn Код:
case DIALOG_MENUSERVER:
        {
            if(response)
            {
                IDL = listitem;
                if(ConfigVal(IDL) == "0" || ConfigVal(IDL) == "1")
                {
                    new params[1];
                    cmd_configmenu(playerid,params);
                }
                else
                {
                    ShowPlayerDialog(playerid,DIALOG_VALORCONFIG,DIALOG_STYLE_INPUT,"Config","Insert new value:","Accept","Exit");
                }
            }
        }
        case DIALOG_VALOROONFIG:
        {
            if(response)
            {
                ServidorInfo[IDL] = inputtext;
            }
        }
Thakns, and sorry for my bad english.
Reply
#2

Hi!

PHP код:
IDL listitem
to
PHP код:
IDL strval(listitem); 
and this:
PHP код:
ServidorInfo[IDL] = strval(inputtext); 
Reply
#3

Quote:
Originally Posted by Mencent
Посмотреть сообщение
Hi!

PHP код:
IDL listitem
to
PHP код:
IDL strval(listitem); 
and this:
PHP код:
ServidorInfo[IDL] = strval(inputtext); 
Errors persist:
pawn Код:
tag mismatch
Line: IDL = strval(listitem);
pawn Код:
argument type mismatch (argument 1)
Line: ServerInfo[IDL] = strval(inputtext);
Reply
#4

Is IDL a string or an integer?
Reply
#5

type Integer:
pawn Код:
new IDL;
Reply
#6

Sorry, it should be like this:
PHP код:
case DIALOG_MENUSERVER:
{
    if(
response)
    {
        
IDL listitem;
        if(
ConfigVal(IDL) == "0" || ConfigVal(IDL) == "1")
        {
            new 
params[1];
            
cmd_configmenu(playerid,params);
        }
        else
        {
            
ShowPlayerDialog(playerid,DIALOG_VALORCONFIG,DIALOG_STYLE_INPUT,"Config","Insert new value:","Accept","Exit");
        }
    }
}
case 
DIALOG_VALORCONFIG:
{
    if(
response)
    {
        
ServidorInfo[IDL] = strval(inputtext);
    }

Reply
#7

Quote:
Originally Posted by Mencent
Посмотреть сообщение
Sorry, it should be like this:
PHP код:
case DIALOG_MENUSERVER:
{
    if(
response)
    {
        
IDL listitem;
        if(
ConfigVal(IDL) == "0" || ConfigVal(IDL) == "1")
        {
            new 
params[1];
            
cmd_configmenu(playerid,params);
        }
        else
        {
            
ShowPlayerDialog(playerid,DIALOG_VALORCONFIG,DIALOG_STYLE_INPUT,"Config","Insert new value:","Accept","Exit");
        }
    }
}
case 
DIALOG_VALORCONFIG:
{
    if(
response)
    {
        
ServidorInfo[IDL] = strval(inputtext);
    }

Error:
pawn Код:
tag mismatch
Line: ServidorInfo[IDL] = strval(inputtext);
Reply
#8

pawn Код:
ServidorInfo[IDL] = SI:strval(inputtext);
or

pawn Код:
enum sI
{
    MaxPing, // INDEX 0
    MaxPacket, // INDEX 1
    MinFPS // INDEX 2
};
new ServerInfo[sI];

ServerInfo[0] = value;
Notice the lower case first letter in enum name.

Also if inputtext is something other than 0, 1, 2, you'll get invalid array index access, crashing your server, so better sanitize/validate input first.
Reply
#9

Integers can't be directly used to specify which enum is being called since they can have different sizes.

Код:
ServidorInfo[SI:0] = strval(inputtext);
Is actually:
Код:
ServidorInfo[MaxPing] = strval(inputtext);
And your code is wrong, this is how you should do it:
pawn Код:
case DIALOG_MENUSERVER:
        {
            if(response)
            {
                if(ConfigVal(listitem) == "0" || ConfigVal(listitem) == "1")
                {
                    new params[1];
                    cmd_configmenu(playerid,params);
                }
                else
                {
                    ShowPlayerDialog(playerid,DIALOG_VALORCONFIG,DIALOG_STYLE_INPUT,"Config","Insert new value:","Accept","Exit");
                }
            }
        }
        case DIALOG_VALOROONFIG:
        {
            if(response)
            {
                ServidorInfo[SI:listitem] = inputtext;
            }
        }
Reply
#10

Quote:
Originally Posted by Gammix
Посмотреть сообщение
Integers can't be directly used to specify which enum is being called since they can have different sizes.

Код:
ServidorInfo[SI:0] = strval(inputtext);
Is actually:
Код:
ServidorInfo[MaxPing] = strval(inputtext);
And your code is wrong, this is how you should do it:
pawn Код:
case DIALOG_MENUSERVER:
        {
            if(response)
            {
                if(ConfigVal(listitem) == "0" || ConfigVal(listitem) == "1")
                {
                    new params[1];
                    cmd_configmenu(playerid,params);
                }
                else
                {
                    ShowPlayerDialog(playerid,DIALOG_VALORCONFIG,DIALOG_STYLE_INPUT,"Config","Insert new value:","Accept","Exit");
                }
            }
        }
        case DIALOG_VALOROONFIG:
        {
            if(response)
            {
                ServidorInfo[SI:listitem] = inputtext;
            }
        }
It shows values that have nothing to do with the stored in the variable.

Thanks for all !!
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)