SA-MP Forums Archive
Array out of bounds; Referencing enum problem? - 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: Array out of bounds; Referencing enum problem? (/showthread.php?tid=436862)



Array out of bounds; Referencing enum problem? - Hoborific - 13.05.2013

pawn Код:
enum pStats{
    Money,
    Level,
    Admin,
    Password[128],
}
new PlayerStats[MAX_PLAYERS][pStats],Car[MAX_PLAYERS];
pawn Код:
forward LoadAccount(playerid);
public LoadAccount(playerid)
{
    new Player[MAX_PLAYER_NAME],File[128];
    GetPlayerName(playerid, Player, sizeof(Player) );
    format(File,sizeof(File),"\\Accounts\\%s.ini", Player);

    PlayerStats[playerid][Password] = dini_Get(File,"Password");
    return 1;

}
Код:
../NGZ/Functions.pwn(143) : error 047: array sizes do not match, or destination array is too small
It's hashed, but it's hashed as a string, i.e = including letters and symbols, I might just use whirlpool and an int.


Re : Array out of bounds; Referencing enum problem? - DaTa[X] - 13.05.2013

pawn Код:
enum pStats{
    Money,
    Level,
    Admin,
    Password[128] // no need to add the , here
};
or this
pawn Код:
PlayerStats[playerid][Password] = (dini_Get(File,"Password"));
not sure


Re: Array out of bounds; Referencing enum problem? - Pottus - 13.05.2013

If i'm not mistaken, I think you need a size of 129.

@DaTa[X] the extra "," character won't cause any problems in a enum


Re: Array out of bounds; Referencing enum problem? - Hoborific - 13.05.2013

pawn Код:
new newpass[64];
pawn Код:
format(newpass,sizeof(newpass),"%s",inputtext);
pawn Код:
dini_Set(File,"Password",newpass);
pawn Код:
PlayerStats[playerid][Password] = dini_Get(File,"Password");
Код:
../NGZ/Functions.pwn(143) : error 047: array sizes do not match, or destination array is too small
Password in the enum is now [135], same problem.


Re: Array out of bounds; Referencing enum problem? - [HiC]TheKiller - 13.05.2013

OK guys, dini_Get returns a string. You cant (like other languages) just do this:

pawn Код:
new string[55], stringtest[56];
string = "hello";
stringtest = string;
It just doesn't work. You have to use a function like format, or strcat or the following function (made by ******):

pawn Код:
#define strcpy(%0,%1,%2) \
    strcat((%0[0] = '\0', %0), %1, %2) //Top of your code
    strcpy(PlayerStats[playerid][Password], dini_Get(File,"Password"), 128);



Re: Array out of bounds; Referencing enum problem? - Hoborific - 13.05.2013

Interesting, thanks for that, I actually increased the string size to 256 and it copied without complains but I don't want the memory implications later on, I'll give the strcpy a go, thank you very much.