AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   array index out of bounds (https://forums.alliedmods.net/showthread.php?t=12395)

Bone 04-14-2005 18:01

array index out of bounds
 
I am trying edit Ava's plugin so the new ATMS in mecklenburg work, the code i put in was

Code:
 new bankposX[3] = { -2504, 680, 275 };  new bankposY[3] = { 1072,-430, -430 };  new bankposZ[3] = { -400, -345, -345 };  new bankposA[3] = { 585, -778, 292 };  new bankposB[3] = { -2135, 2642, -344 };  new bankposC[3] = { -3605, 2645, -1179 };

Code:
        }         new origin[3], checkorigin[3], validpos;         get_user_origin(id,origin);         // check if player is near an ATM         for(new i=0;i<sizeof(bankposX);i++) {             checkorigin[0] = bankposX[i];             checkorigin[1] = bankposY[i];             checkorigin[2] = bankposZ[i];                         checkorigin[3] = bankposA[i];                         checkorigin[4] = bankposB[i];                         checkorigin[5] = bankposC[i];             if(get_distance(origin,checkorigin) <= 48) {                 validpos = 1;             }         }

and i get array index out of bounds which is somehow being caused by the new backposA,B and C arrays, can someone please help my problem. thanks

xeroblood 04-14-2005 18:19

Re: array index out of bounds
 
Quote:

Originally Posted by Bone
I am trying edit Ava's plugin so the new ATMS in mecklenburg work, the code i put in was

Code:
//[...]     new checkorigin[3] // [...]     checkorigin[3] = bankposA[i];     checkorigin[4] = bankposB[i];     checkorigin[5] = bankposC[i]; // [...]

and i get array index out of bounds which is somehow being caused by the new backposA,B and C arrays, can someone please help my problem. thanks

:roll: (look at indexes..)

Bone 04-14-2005 19:12

what?

what do you mean

v3x 04-14-2005 21:16

Edit:

x Removed by me

XxAvalanchexX 04-14-2005 22:13

v3x, do you even understand what you tell people?!

Creating an array with 5 dimensions and then using a function to compare vectors (3 dimensions) is supposed to work?

v3x 04-14-2005 22:26

Oh, I misread it. :|

xeroblood 04-14-2005 23:12

Quote:

Originally Posted by Bone
what?

what do you mean

What I meant was that you tried to access an index of the array that is out-of-bounds.. fortunately, that is exactly what the compiler tells you!! :D

If you declare an array of 3 values, then you can only access the array with 3 indexes (namely: 0, 1, 2)

But what you did is create an array of 3, and then tried accessing 6 indexes (namely: 0, 1, 2, 3, 4, 5).. look here in your code:

Code:
 new origin[3], checkorigin[3], validpos; //[...]             checkorigin[0] = bankposX[i];             checkorigin[1] = bankposY[i];             checkorigin[2] = bankposZ[i];             checkorigin[3] = bankposA[i];             checkorigin[4] = bankposB[i];             checkorigin[5] = bankposC[i];

The 'checkorigin' is only an array of 3, but you are trying to access 6 indexes..

Solution: make two different arrays of 3, or make the one array an array of 6.. :D

I hope that helps..

Twilight Suzuka 04-15-2005 10:24

A better solution would be to make some sort of system for which to lay your own NPC's, instead of hard coding coordinates, and then loading the saved NPC's on server start.

Also, it would be really cool if the NPC's moved, if you could set their model in game, tell them what to say in game, make them allsay and do and be different things, and if they were hooked into a working inventory mod.

http://forums.alliedmods.net/showthread.php?t=5037

Bone 04-15-2005 11:00

ok i made neworigin and origin 6 like

Code:
new origin[6], checkorigin[6], validpos; //[...]             checkorigin[0] = bankposX[i];             checkorigin[1] = bankposY[i];             checkorigin[2] = bankposZ[i];             checkorigin[3] = bankposA[i];             checkorigin[4] = bankposB[i];             checkorigin[5] = bankposC[i];

but it says array sizes must match AND array index is out of bounds ....

xeroblood 04-15-2005 11:14

You'll need to post more of your code so we can see whats going on..


All times are GMT -4. The time now is 09:50.

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