AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Dynamic Array run time error (https://forums.alliedmods.net/showthread.php?t=329914)

krisztian2 01-13-2021 06:23

Dynamic Array run time error
 
Dear scripters!

I have a problem with this array, because the server logged this error message:
[AMXX] Run time error 10: native error (native "ArrayGetCell")
I filled array with numbers.
So 2 line here:
Code:

new random_number = random_num(0,ArraySize( g_aArray ));
new iRand = ArrayGetCell( g_aArray, random_number ); //This line got error.

Sincerely, krisztian2.

OciXCrom 01-13-2021 07:30

Re: Dynamic Array run time error
 
Use "random" instead of "random_num".
"random_num" uses an inclusive maximum value, so your value goes out of bounds.

Bugsy 01-13-2021 08:24

Re: Dynamic Array run time error
 
Yes, random( 10 ) would give you a value from 0 to 9 so for array index purposes it's perfect. Use random() with ArraySize() inside of it.


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

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