Ban system error - array index out of bounds
#1

Hello! I have coded a ban system. When I try to compile it, it gives me the following errors:
Код:
egaming.pwn(311) : error 075: input line too long (after substitutions)
egaming.pwn(312) : error 032: array index out of bounds (variable "BanMenu")
egaming.pwn(313) : warning 217: loose indentation
egaming.pwn(313) : error 017: undefined symbol "nu"
egaming.pwn(313) : warning 215: expression has no effect
egaming.pwn(313) : error 001: expected token: ";", but found "]"
egaming.pwn(313) : error 029: invalid expression, assumed zero
egaming.pwn(313) : fatal error 107: too many error messages on one line
Lines 311-313:
pawn Код:
new string[494];
format(string, sizeof(string), "{FFCE39}The following settings will be applied for your ban. Do you want to continue?\n\n{FFCE39}Player: {FFF1AF}%s\n{FFCE39}Ban Type: {FFF1AF}temporary\n{FFCE39}Reason: {FFF1AF}%s\n{FFCE39}Duration years: {FFF1AF}%i\n{FFCE39}Duration months: {FFF1AF}%i\n{FFCE39}Duration weeks: {FFF1AF}%i\n{FFCE39}Duration days: {FFF1AF}%i\n{FFCE39}Duration hours: {FFF1AF}%i\n{FFCE39}Duration minutes: {FFF1AF}%i", returnname(BanMenu[playerid][TargetID]), BanMenu[playerid][Reason], BanMenu[playerid][D_Years], BanMenu[playerid][D_Months], BanMenu[playerid][D_Weeks], BanMenu[playerid][D_Days], BanMenu[playerid][D_Hours], BanMenu[playerid][D_Minutes]);
return ShowPlayerDialog(playerid, DIALOG_BANMENU_EXEC, DIALOG_STYLE_LIST, "Ban Menu", string, "Ban", "Cancel");
BanMenu variable declaration:
pawn Код:
enum BanData
{
    TargetID = INVALID_PLAYER_ID,
    bool:Permanent = false,
    Reason[65],
    D_Years = 0,
    D_Months = 0,
    D_Weeks = 0,
    D_Days = 0,
    D_Hours = 0,
    D_Minutes = 0
}

new BanMenu[MAX_PLAYERS][BanData];
What's wrong with my code?
Reply
#2

You write a too long line. Try:
pawn Код:
new string[494];
format(string, sizeof(string), "{FFCE39}The following settings will be applied for your ban. Do you want to continue?\n\n{FFCE39}Player: {FFF1AF}%s\n{FFCE39}Ban Type: {FFF1AF}temporary\n{FFCE39}Reason: {FFF1AF}%s\n{FFCE39}Duration years: {FFF1AF}%i\n{FFCE39}Duration months: {FFF1AF}%i\n{FFCE39}Duration weeks: {FFF1AF}%i\n{FFCE39}Duration days: {FFF1AF}%i\n{FFCE39}Duration hours: {FFF1AF}%i\n{FFCE39}Duration minutes: {FFF1AF}%i",
returnname(BanMenu[playerid][TargetID]), BanMenu[playerid][Reason], BanMenu[playerid][D_Years], BanMenu[playerid][D_Months], BanMenu[playerid][D_Weeks], BanMenu[playerid][D_Days], BanMenu[playerid][D_Hours], BanMenu[playerid][D_Minutes]);
return ShowPlayerDialog(playerid, DIALOG_BANMENU_EXEC, DIALOG_STYLE_LIST, "Ban Menu", string, "Ban", "Cancel");
Reply
#3

Your format line is just too long, use a second format:

pawn Код:
format(string, sizeof(string), "{FFCE39}The following settings will be applied for your ban. Do you want to continue?\n\n{FFCE39}Player: {FFF1AF}%s\n{FFCE39}Ban Type: {FFF1AF}temporary\n{FFCE39}Reason: {FFF1AF}%s\n{FFCE39}Duration years: {FFF1AF}%i\n{FFCE39}Duration months: {FFF1AF}%i\n{FFCE39}Duration weeks: {FFF1AF}%i\n", returnname(BanMenu[playerid][TargetID]), BanMenu[playerid][Reason], BanMenu[playerid][D_Years], BanMenu[playerid][D_Months], BanMenu[playerid][D_Weeks]);
format(string, sizeof(string), "%s{FFCE39}Duration days: {FFF1AF}%i\n{FFCE39}Duration hours: {FFF1AF}%i\n{FFCE39}Duration minutes: {FFF1AF}%i", string, BanMenu[playerid][D_Days], BanMenu[playerid][D_Hours], BanMenu[playerid][D_Minutes]);
Reply
#4

I have tried that. The error changes to this:
Код:
egaming.pwn(312 -- 313) : error 032: array index out of bounds (variable "BanMenu")
egaming.pwn(319) : error 032: array index out of bounds (variable "BanMenu")
egaming.pwn(324) : error 032: array index out of bounds (variable "BanMenu")
egaming.pwn(326) : error 032: array index out of bounds (variable "BanMenu")
egaming.pwn(326) : error 047: array sizes do not match, or destination array is too small
egaming.pwn(340) : error 032: array index out of bounds (variable "BanMenu")
egaming.pwn(354) : error 032: array index out of bounds (variable "BanMenu")
egaming.pwn(404) : error 032: array index out of bounds (variable "BanMenu")
egaming.pwn(406) : error 032: array index out of bounds (variable "BanMenu")
egaming.pwn(406) : error 047: array sizes do not match, or destination array is too small
egaming.pwn(422) : error 032: array index out of bounds (variable "BanMenu")
egaming.pwn(424) : error 032: array index out of bounds (variable "BanMenu")
egaming.pwn(430) : error 032: array index out of bounds (variable "BanMenu")
egaming.pwn(432) : error 032: array index out of bounds (variable "BanMenu")
egaming.pwn(434) : error 032: array index out of bounds (variable "BanMenu")
egaming.pwn(434) : error 047: array sizes do not match, or destination array is too small
egaming.pwn(635 -- 636) : error 032: array index out of bounds (variable "BanMenu")
egaming.pwn(642) : error 032: array index out of bounds (variable "BanMenu")
In each place that I use variable BanMenu I get this error, so it seems that something is wrong with it, especially with the string within it ("Reason"). Whole code (it is not finished!): http://pastebin.com/7gq7Aw4W
Reply
#5

I'm not sure, but i don't think that you can declare a default value in an enum. Just make:
pawn Код:
enum BanData
{
    TargetID,
    bool:Permanent,
    Reason[65],
    D_Years,
    D_Months,
    D_Weeks,
    D_Days,
    D_Hours,
    D_Minutes
}

new BanMenu[MAX_PLAYERS][BanData];
since as far as i know samp initializes the variable with 0 by default. For the other values you can give them values under OnPlayerConnect or something.
Reply
#6

Thanks! That was the problem. I don't even know why I initialised them there. Now, I only have those errors:
Код:
egaming.pwn(326) : error 047: array sizes do not match, or destination array is too small
egaming.pwn(406) : error 047: array sizes do not match, or destination array is too small
egaming.pwn(434) : error 047: array sizes do not match, or destination array is too small
Line 326/406/434 (they are the same):
pawn Код:
BanMenu[playerid][Reason] = "";
As far as I know, one cannot retrieve an array length from an enum. I think this might be the problem here. Then, how could I delete the string inside that variable?
Reply
#7

There are many ways you can do that, but i simply prefer:

pawn Код:
BanMenu[playerid][Reason][0]=EOS;
EOS or '\0' stands for the null character.
Reply
#8

That's it! Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)