AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [AMXX] Run time error 4 (index out of bounds) (https://forums.alliedmods.net/showthread.php?t=9849)

Shinzon 02-01-2005 11:05

[AMXX] Run time error 4 (index out of bounds)
 
Hi,

need a bit help, error occurs imho here:
Code:
public death_event(id) {     new streak = get_streak()     if ((streak&1) || (streak&2)){     new killer = read_data(1);     new victim = read_data(2);     kills[killer] += 1;     kills[victim] = 0;     deaths[killer] = 0;     deaths[victim] += 1;     for (new i = 0; i < LEVELS; i++) {         if (kills[killer] == levels[i]) {            <------- suspected error here             announce(killer, i);             return PLUGIN_CONTINUE;         }         }     }     return PLUGIN_CONTINUE; }

I don't have any clue, new in scripting, sorry.
Any hints ?

PM 02-01-2005 11:22

How did you define the variables killer and levels?

Shinzon 02-01-2005 11:38

Omg, seen this:

Code:
#define LEVELS 15 new levels[10] = {3, 5, 7, 9, 11, 12, 13, 14, 15, 16};

Maybe this is the error, testing this now.
Thanks.

BAILOPAN 02-01-2005 11:45

Code:
#define LEVELS 15 new levels[10] = {3, 5, 7, 9, 11, 12, 13, 14, 15, 16}; .. for (new i = 0; i < LEVELS; i++) {

You're declaring an array of size 10 and then trying to access 15 slots.

Knare 02-01-2005 12:07

if you are not using a MAC computer then the compiler tells the line with the error by a number before the error/warning

Shinzon 02-01-2005 12:09

comes from:

Code:
#define LEVELS 25 new levels[19] = {3, 5, 7, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25}; new stksounds[19][] = {             "misc/tripplekill",                         "misc/multikill",             "misc/monsterkill",             "misc/megakill",                         "misc/ultrakill",             "misc/ludicrouskill",                         "misc/unstoppable",             "misc/whickedsick",             "misc/godlike",                         "misc/holyshit_en",             "misc/holyshit_en",             "misc/holyshit_en",             "misc/holyshit_en",                         "misc/holyshit_en",             "misc/holyshit_en",                         "misc/holyshit_en",             "misc/holyshit_en",             "misc/holyshit_en",             "misc/holyshit_en"}; new stkmessages[19][] = {                      "%s: Triple-KILL!! (3 in row)",                      "%s Multi-KILL!! (5 in row)",                      "%s Monster-KILL!! (7 in row)",                      "%s Mega-KILL!! (9 in row)",                      "%s Ultra-KILL!! (11 in row)",                      "%s Ludicrous-KILL!! (12 in row)",                      "%s UNSTOPPABLE!! (13 in row)",                      "%s WICKED SICK!! (14 in row)",                      "%s GODLIKE!! (15 in row)",                      "%s HOLY SHIT!!! (16 in row)",                      "%s HOLY SHIT!!! (17 in row)",                      "%s HOLY SHIT!!! (18 in row)",                      "%s HOLY SHIT!!! (19 in row)",                      "%s HOLY SHIT!!! (20 in row)",                      "%s HOLY SHIT!!! (21 in row)",                      "%s HOLY SHIT!!! (22 in row)",                      "%s HOLY SHIT!!! (23 in row)",                      "%s HOLY SHIT!!! (24 in row)",                      "%s HOLY SHIT!!! (25 in row)"};

If i set
Code:
new levels[25] = {3, 5, 7, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25};
get an internal error on compiling, with 19 it compiled without errors.

Geesu 02-01-2005 13:00

thats b/c u only have 19 values in that array, not 25, add 6 more values and you won't get a compiler error

Shinzon 02-01-2005 13:15

Then i get:

Code:

c:\amxx windows\scripting\sounds.sma(71) : error 018: initialization data exceeds declared size
hmmmm.....weird....

havn't written this plugin by myself, comes from amx, only changes i have made are different sounds...

Geesu 02-01-2005 13:19

then add 5 values, not 6

Shinzon 02-01-2005 13:23

1 Attachment(s)
Sorry, same result.

Have attached the sma, maybe you can have a look at....


All times are GMT -4. The time now is 19:17.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.