Raised This Month: $ Target: $400
 0% 

ArraySetString Error


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SYNC1223
Junior Member
Join Date: Sep 2013
Old 10-01-2013 , 11:46   ArraySetString Error
Reply With Quote #1

Hello guys!
I have a problem with this:
PHP Code:
#include <amxmodx>

new Array:array;

public 
plugin_init() {

array = 
ArrayCreate(32,32);

for(new 
0ArraySize(array); i++) 
ArrayPushString(array,"null");
}

public 
client_connect(id) {

new 
name[32];
get_user_name(id,name,31);
ArraySetString(array,id,name);


It shows me error in console:
Quote:
L 10/01/2013 - 17:45:44: Invalid cellvector handle provided (10:1:0)
L 10/01/2013 - 17:45:44: [AMXX] Displaying debug trace (plugin "test.amxx")
L 10/01/2013 - 17:45:44: [AMXX] Run time error 10: native error (native "ArraySetCell")
L 10/01/2013 - 17:45:44: [AMXX] [0] test.sma::client_connect

Last edited by YamiKaitou; 10-02-2013 at 18:15.
SYNC1223 is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 10-01-2013 , 12:52   Re: ArraySetString Error
Reply With Quote #2

Your Array items are from 0 to 31.
Player IDs are from 1 to 32.
__________________
hleV is offline
SYNC1223
Junior Member
Join Date: Sep 2013
Old 10-01-2013 , 14:09   Re: ArraySetString Error
Reply With Quote #3

@hleV, i have changed ArrayCreate(32,32) to ArrayCreate(32,33) but the errors are appearing still.
SYNC1223 is offline
guipatinador
SourceMod Donner Party
Join Date: Oct 2009
Location: Poortugal
Old 10-01-2013 , 15:05   Re: ArraySetString Error
Reply With Quote #4

Your error log shows "ArraySetCell" but your plugin shows "ArraySetString". What are you trying to do?

Last edited by guipatinador; 10-01-2013 at 15:06.
guipatinador is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 10-01-2013 , 17:56   ArraySetString Error
Reply With Quote #5

The first number is the handle. The second number is requested index. The third number is size, which is 0. You have no entries.

ArraySize() will most likely return 0 upon creation so you never push any strings, "initializing" it. Creating an array with 32 indexes in ArrayCreate() is just a memory reservation, not actual entries.

Replace "< ArraySize()" with "<= 32" or maxclients if you want to do it completely correctly.
__________________

Last edited by Black Rose; 10-02-2013 at 05:01.
Black Rose is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 10-02-2013 , 04:39   Re: ArraySetString Error
Reply With Quote #6

You shouldn't be calling ArraySize() in a loop anyway - cache the value before it.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
SYNC1223
Junior Member
Join Date: Sep 2013
Old 10-02-2013 , 13:10   Re: ArraySetString Error
Reply With Quote #7

@Black Rose & @hornet, thanks i understand it solved
SYNC1223 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 10-02-2013 , 15:32   Re: Solved
Reply With Quote #8

Don't remove the question. It might be helpful for others searching for answers.
__________________
Black Rose is offline
Reply



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 22:32.


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