Raised This Month: $ Target: $400
 0% 

Arrays


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-21-2013 , 04:37   Re: Arrays
Reply With Quote #7

Your example doesn't delete the position 2, it deletes whatever position contains the value 2.
If you're going to post an example instead of your actual code, make sure that the example can produce the error.

I'm gonna guess that your actual loop doesn't contain break. Because then you will get that error unless you account for the removed entries.

Code:
/**  * Deletes an item from the array.  All items beyond it get shifted down 1 space.  *  * @param which         The array that contains the item to delete.  * @param item          The item to delete.  */ native ArrayDeleteItem(Array:which, item);

Code:
#include <amxmodx> public plugin_init() {     register_plugin("Test Plugin 6", "", "");         new Array:hArray = ArrayCreate(1,1);         for ( new i = 1 ; i <= 5 ; i++ )         ArrayPushCell(hArray, i);         new size = ArraySize(hArray);         for ( new i = 0 ; i < size ; i++ )         server_print("PRE: %d: %d", i, ArrayGetCell(hArray, i));         new deleted_items;         for ( new i = 0 ; i < size ; i++ ) {         server_print("Reading cell %d with value of %d", i - deleted_items, ArrayGetCell(hArray, i - deleted_items));         if ( ArrayGetCell(hArray, i - deleted_items) == 3 )             ArrayDeleteItem(hArray, i - deleted_items++);     }         size = ArraySize(hArray);     for ( new i = 0 ; i < size ; i++ )         server_print("POST: %d: %d", i, ArrayGetCell(hArray, i)); }

Code:
PRE: 0: 1
PRE: 1: 2
PRE: 2: 3
PRE: 3: 4
PRE: 4: 5
Reading cell 0 with value of 1
Reading cell 1 with value of 2
Reading cell 2 with value of 3
Reading cell 2 with value of 4
Reading cell 3 with value of 5
POST: 0: 1
POST: 1: 2
POST: 2: 4
POST: 3: 5
__________________
Black Rose is offline
 



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 19:03.


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