Enum Issue -
#1

Anyone know why I get these warning / error? I used enum as I did [][] and printing the value for [i][1] prints invalid results, not the correct data... But prints right data for [i][0]

warning 228: length of initialler exceeds size of the enum field
error 018: initialization data exceeds declared size

Код:
enum Data
{
	SmallCode[5],
	LongerCode[60],
}

new TenCodes[][Data] =
{
    {"10-00","Use Caution (10%00)"},
    {"10-01","Signal Week (10%01)"},
    {"10-02","Signal Good (10%02)"},
    {"10-03","Stop transmitting (10%03)"},
    {"10-04","Okay, Affirmative (10%04)"}
};
Thanks
Reply
#2

Quote:
Originally Posted by ******
Посмотреть сообщение
1) Your strings are 6 characters, not 5.

2) ENUMS. ARE. NOT. ARRAYS.

I wonder if there's a way to see how many HUNDREDS of times I've said that!
I changed it back to arrays, and look:

The result:

(There is more 10 codes in the array, I moved them out so it doesn't become too long.

The print for the TenCodes[i][1] isn't correct. It just prints the code without the 1, so 0-20, not the whole string.

[08:53:06] 20 - Found - Replacing 10-20 with 0-20 within hello 10-20

Код:
stock IncludeCodes(playerid, chattext2[])
{
	new chattext[180];

	format(chattext, sizeof(chattext), chattext2);

	for(new i = 0; i < sizeof(TenCodes); i++)
	{
		if(strfind(chattext, TenCodes[i][0], true) != -1)
		{
		    printf("%d - Found - Replacing %s with %s within %s", i, TenCodes[i][0], TenCodes[i][1], chattext);
            strreplace2(chattext, TenCodes[i][0], TenCodes[i][1],true);
            printf(" ");
		}
	}
}
Reply
#3

pawn Код:
enum Data
{
    SmallCode[5],
    LongerCode[60],
}
You are using ENUM for arrays man,this is not what enums are for XD
Reply
#4

Quote:
Originally Posted by ******
Посмотреть сообщение
What do you mean you changed it back to arrays?
I removed the enum codee and replaced it with: new TenCodes[][] = { blabla };

Then using TenCodes[i][0] and TenCodes[i][1].

But the [1] doesn't print the right values, it just prints the 10code but as 0-20 or 0-25 even though it should print the full string name.
Reply
#5

Quote:
Originally Posted by KyleSmith
Посмотреть сообщение
I removed the enum codee and replaced it with: new TenCodes[][] = { blabla };

Then using TenCodes[i][0] and TenCodes[i][1].

But the [1] doesn't print the right values, it just prints the 10code but as 0-20 or 0-25 even though it should print the full string name.
You miss the lenght. Have a look at Beginner's Guide: Single/Two/Multi-dimensional Arrays
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)