Raised This Month: $202 Target: $400
 50% 

Dynamic Array run time error


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
krisztian2
Junior Member
Join Date: Feb 2019
Old 01-13-2021 , 07:23   Dynamic Array run time error
Reply With Quote #1

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.
krisztian2 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-13-2021 , 08:30   Re: Dynamic Array run time error
Reply With Quote #2

Use "random" instead of "random_num".
"random_num" uses an inclusive maximum value, so your value goes out of bounds.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-13-2021 , 09:24   Re: Dynamic Array run time error
Reply With Quote #3

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.
__________________
Bugsy is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 14:48.


Powered by vBulletin®
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Theme made by Freecode