Raised This Month: $32 Target: $400
 8% 

Solved Function array parameter returns array values 0


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
AnimalMonster
Senior Member
Join Date: May 2020
Old 02-07-2023 , 15:16   Function array parameter returns array values 0
Reply With Quote #1

So, i made some sorting algorithm based on sorting alphabetically but symbols first in line, numbers second and letters last. I have some arrays with some numbers which stand for item ids registered in my plugin, i set the arrays based on some conditions and then introduce the array into the function which sorts the array. At the start of the function i checked what is in that array and i see that everything (for a specific number of items representing the items in the field) and see that everything is empty, why?

In the first lines of the function 'SortItemArray' you can see that i checked the array for its item ids and in 'InitSort' that i sorted the arrays (2 arrays with 3 dimensions) in 3 for-loops (no the best idea, it could be easier in 2 but still not the problem).

PHP Code:
SortItemArray( const Sortmtd, const SortDirdir, const Category, array[ ] )
{
    
server_print("[Buymenu] items in array to sort for category %s"g_CategName[Category]);

    for(new 
0g_iCategItems[Category]; h++)
        
server_print("[Buymenu] %i", array[h]);

    if(
g_iCategItems[Category] <= 1)
    {
        
server_print("[Buymenu] Not enough items to sort.");
        return;
    }

    new 
ijd;

    if ( 
mtd == Sort_Name )
    {
        new 
szName30 ], szName230 ];

        for ( 
0g_iCategItems[Category]; i++ )
        {
            
ArrayGetStringg_ItemDataIRD_Name ], array[ ], szName2charsmaxszName2 ) );

            for ( 
0sizeof g_szMenuCodesd++ )
            {
                if ( 
containszNameg_szMenuCodes] ) )
                    
replace_allszNamecharsmaxszName ), g_szMenuCodes], "");
            }

            for ( 
i+1g_iCategItems[Category]; j++ )
            {
                
ArrayGetStringg_ItemDataIRD_Name ], array[ ], szName2charsmaxszName2 ) );

                for ( 
0sizeof g_szMenuCodesd++ )
                {
                    if ( 
containszName2g_szMenuCodes] ) )
                        
replace_allszName2charsmaxszName2 ), g_szMenuCodes], "");
                }

                if ( 
CompareStringsszName2szNamedir ) > )
                {
                   
inverse_values( array[ ], array[ ] );
                }
            }
        }
    }
    else if ( 
mtd == Sort_Cost )
    {
        
server_print("[Buymenu] Sorting by Cost:");
        new 
iCost];
        new 
szSysName[2][20];

        for ( 
0g_iCategItems[Category]; i++)
        {
            for ( 
i+1g_iCategItems[Category]; j++ )
            {
                
iCost] = ArrayGetCellg_ItemDataIRD_Cost ], array[ ] );
                
iCost] = ArrayGetCellg_ItemDataIRD_Cost ], array[ ] );

                
ArrayGetStringg_ItemDataIRD_SystemName ], array[i], szSysName[0], charsmax(szSysName[]) );
                
ArrayGetStringg_ItemDataIRD_SystemName ], array[i], szSysName[1], charsmax(szSysName[]) );

                
server_print("[Buymenu] %s vs %s"szSysName[0], szSysName[1]);

                if ( ( 
iCost] > iCost] && dir == SRDir_Ascendent ) ||
                    ( 
iCost] < iCost] && dir == SRDir_Descendent ) )
                {
                    
inverse_values( array[ ], array[ ] );
                }

                
server_print("[Buymenu] Next: ^n^n");
            }
        }
    }
}

InitSort( )
{
    new 
szSysName[20];
    for ( new 
0CATEGORIESi++ )
    {
        for ( new 
SortDir:SortDir:0SortDirx++ )
        {
            for ( new 
0g_iItemsz++ )
            {
                if ( 
ArrayGetCellg_ItemDataIRD_Category ], ) != )
                    continue;

                
ArrayGetStringg_ItemDataIRD_SystemName ], zszSysNamecharsmax(szSysName) );

                
server_print("[Buymenu] %s is part of %s (Id: %i)"szSysNameg_CategName[i], z);

                
g_iSortedItemsCost][ ][ ] = z;
                
g_iSortedItemsName][ ][ ] = z;
            }

            
SortItemArraySort_Costxig_iSortedItemsCost][ ] );
            
SortItemArraySort_Namexig_iSortedItemsName][ ] );
        }
    }

    for ( new 
0CATEGORIESi++ )
    {
        for ( new 
0g_iCategItems[i]; z++ )
        {
            
ArrayGetStringg_ItemDataIRD_SystemName ], g_iSortedItemsCost[i][SRDir_Ascendent][z], szSysNamecharsmax(szSysName) );

            
server_print("[Buymenu] Category %s by Cost: %i. %s"g_CategName[i], zszSysName);
        }
    }

Solved
I was setting the same cell in the third dimension.

Last edited by AnimalMonster; 02-07-2023 at 17:29.
AnimalMonster 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 17:16.


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