SA-MP Forums Archive
array index out of bounds??? - 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 index out of bounds??? (/showthread.php?tid=287193)



array index out of bounds??? - knackworst - 02.10.2011

hi,
I am busy making my first enums to make easier jobs in my server
Whit the help from NERO_3D I made part one of the job
part one of the job creates a random job, wich sets a random cp according to the random job
for the random job I made this enum:
pawn Код:
enum DMissions
{
    mission_name[200],
    mission_nickname[200],
    person_name[200],
    pick_place[50],
    deliver_place[50],
    mission_type,
    Float:pick_x,
    Float:pick_y,
    Float:pick_z,
    Float:deliver_x,
    Float:deliver_y,
    Float:deliver_z
};
and
pawn Код:
new const Mission1[5][DMissions]=
{
//==============================================================================
//Mission TYPE 1
//==============================================================================
    {"~g~~h~~h~Travis Pastrana~n~~w~Is Going to participate the X-games",   "Travis is a beast!",   "Travis Pastrana""The Hollywood Hotel",  "The Stadium"1,
    334.4390,-1519.8026,35.7015,
    2732.6616,-1841.6346,9.9145},
   
    {"~g~~h~~h~Chris Martin~w~ is back from his smash concert~n~ in the Stadium ~n~VIVA LA VIDA man!""VIVA LA VIDA!",    "Chris Martin", "The Stadium",  "Chris Martin's Hotel",  1,
    2732.6616,-1841.6346,9.9145,
    1737.9714,-1270.4094,13.5441},
   
    {"Pick ~g~~h~~h~George Clooney~w~ ~n~from the Los Santos Studios~n~he has just filmed the nespresso spot""Nespresso, What Else?",    "George Clooney",   "Los Santos Studios",  "George Clooney's house",  1,
    894.0326,-1217.7205,17.1052,
    707.0739,-1701.8639,3.5777},
   
    {"~g~~h~~h~Michael Phelps~w~ is faster than a dolphin!",    "He's faster than a killer whale!", "Michael Phelps",   "Michael Phelps' House",  "The Swimming Pool",  1,  \
    804.7731,-1730.7510,13.5849,
    885.3402,-1757.8971,13.6774},
   
    {"~g~~h~~h~Nasty Dominic", "Nasty nasty pervert...",    "Dominique Khan",       "His Hotel",  "CourtHouse",  1, \
    334.4390,-1519.8026,35.7015,
    1542.6808,-1674.7144,13.5550}
};
the part one of the job, code:
pawn Код:
// messages
            format(string, sizeof string, "Mission: {FF6347}%s", Mission1[rand][mission_nickname]);
            SendClientMessage(playerid, COLOR_SEXYGREEN, string);
            SendClientMessage(playerid, COLOR_SEXYGREEN, "|==========================================================|");
            SendClientMessage(playerid, COLOR_SEXYGREEN, "A {FF6347}Level 1 {00FF00}Driving Mission");
            format(string, sizeof string, "Bring: {4169FF}\"%s\" {00FF00}From {4169FF}\"%s\" {00FF00}To {4169FF}\"%s\"", Mission1[rand][person_name],Mission1[rand][pick_place],Mission1[rand][deliver_place]);
            SendClientMessage(playerid, COLOR_SEXYGREEN, string);
            // MapIcon
                mx = Mission1[rand][pick_x];
                my = Mission1[rand][pick_y];
                mz = Mission1[rand][pick_z];
            Mmic = CreateDynamicMapIcon(mx, my, mz, 53, 0, -1,-1, playerid, MAPICON_GLOBAL);
            Mcheck[0] = CreateDynamicCP(mx, my, mz, 2.0, -1, -1, playerid, 100.0);
            // variables
            Mission1[rand][DMissions] = jInfo[rand][DMissions];
ok so I do get the clientmessages properly ingame
next I had to add some variable to use the random job info that is used at the moment
so I made jInfo
pawn Код:
enum JobInfo
{
    JI_mission_name[200],
    JI_mission_nickname[200],
    JI_person_name[200],
    JI_pick_place[50],
    JI_deliver_place[50],
    JI_mission_type,
    JI_Float:pick_x,
    JI_Float:pick_y,
    JI_Float:pick_z,
    JI_Float:deliver_x,
    JI_Float:deliver_y,
    JI_Float:deliver_z

};
new jInfo[MAX_PLAYERS][JobInfo];
but now when I compile I get this error and warnings:
Код:
William\Documents\Famous' World\Famous' World\gamemodes\Famous.pwn(5855) : error 032: array index out of bounds (variable "Mission1")
line:
pawn Код:
Mission1[rand][DMissions] = jInfo[rand][JobInfo];
the thing to get the information out of the variable under onplayerneterdynamicCP
pawn Код:
if(checkpointid == Mcheck[0])
    {
        format(string, sizeof string, "Mission: {FF6347}%s", jInfo[rand][mission_nickname]);//just to test if i get the info out of the var
        SendClientMessage(playerid, COLOR_SEXYGREEN, string);
    }
and here i get this message:
Код:
tag mistach
line: format(string, sizeof string, "Mission: {FF6347}%s", jInfo[rand][mission_nickname]);

thanks in advance


Re: array index out of bounds??? - Vince - 02.10.2011

So where does rand get calculated?


Re: array index out of bounds??? - knackworst - 02.10.2011

pawn Код:
StartDriverMissionForPlayer(playerid,level)
{
    new string[1000];
    new rand = random(sizeof Mission1);
    new rand2 = random(sizeof Mission2);
    new rand3 = random(sizeof Mission3);
    new Float:mx, Float:my, Float:mz;
    // default messages for all different types
    SendClientMessage(playerid, COLOR_SEXYGREEN, " ");
    SendClientMessage(playerid, COLOR_SEXYGREEN, " ");
    SendClientMessage(playerid, COLOR_SEXYGREEN, "|==========================================================|");

    if(gTeam[playerid] == TEAM_DRIVERS && level == 1)
    {
        if(Mission1[rand][mission_type] == 1)
        {
            // messages
            format(string, sizeof string, "Mission: {FF6347}%s", Mission1[rand][mission_nickname]);//more code, that u saw earlier