alliedmodders / amxmodx

AMX Mod X - Half-Life 1 Scripting and Administration
http://www.amxmodx.org/
496 stars 197 forks source link

Add ArrayIsArrayHandle #1062

Open gtteamamxx opened 2 years ago

gtteamamxx commented 2 years ago

Hello.

For now we have in #include <cellarray> many natives which are awesome but there's missing one.

Let's assume you just created an array by code:

new Array:array = ArrayCreate();

and then You added some items to it:

ArrayPushCell(array, 0);
ArrayPushCell(array, _:ArrayCreate()); // note: you passed an array handle

now how to check if item at index 1 is exactly an Array type?

Right now I can't do for example this simple logic

new size = ArraySize(array);
for(new i = 0; i < size; ++i)
{
    new item = ArrayGetCell(array, i);

    if(item is array) // we can't check if it's an array handle
    {
         new innerArraySize = ArraySize(Array:item);
    }
}

So my proposal is to add new native which can't be done by plugin. It has to be implemented inside amx

/* Returns true if item is an Array handle, false otherwise */
public native bool:ArrayIsArrayHandle(item); 
SmirnoffBG commented 1 year ago

why do u need a function to check if an array item is an array :D First if u want it, u can do just a separate array just for array handles. Second: its very hard to know if the slot has the array handle 1 or just a number 1, which means that a whole new argument should be to declare every added item if its an int or handle which is very useless. If u want it u can do it in pawn but it will be with both things i mentioned. Create a func like "AddItem( Item, bool: IsArrayHandle) and if its an array just add it in to the other array :D