Raised This Month: $ Target: $400
 0% 

Dynamic arrays string sorting


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
tm.
Member
Join Date: Apr 2010
Old 09-03-2010 , 10:30   Dynamic arrays string sorting
Reply With Quote #1

Hi. I wrote a plugin to list all the maps from the maps folder, but I have a problem with sorting the list. I managed to sort them, using the Exolent's code from here, but I think what I've made looks messy.
I was wondering what's the best way for sorting dynamic string arrays?

Here's the part of the code in question:
PHP Code:
public SortMaps(Array:g_MapsArrayiItem1iItem2, const iData[])
{
    static 
iData1[5], iData2[5]; // first 5 elements should be enough

    
ArrayGetString(g_MapsArrayiItem1iData1charsmax(iData1));
    
ArrayGetString(g_MapsArrayiItem2iData2charsmax(iData2));

    new 
iCount1 iData1[0]; // gets the first letter of the map name('d' for 'de_dust2')
    
new iCount2 iData2[0]; // -//- ('d' for 'de_inferno')

    
if(iCount1 != iCount2// in this example 'd' equals 'd'
    
{
        return (
iCount1 iCount2) ? : -1;
    }

    
iCount1 iData1[1];
    
iCount2 iData2[1];

    if(
iCount1 != iCount2// 'e' equals 'e'
    
{
        return (
iCount1 iCount2) ? : -1;
    }

    
iCount1 iData1[3];
    
iCount2 iData2[3];

    
// 'd' != 'i' but this it's not good cause some maps could have a 3 letter prefix (awp_)
    // then I'd need to repeat the above process
    
return (iCount1 iCount2) ? : ((iCount1 iCount2) ? -0);

The entire code it's attached.
Attached Files
File Type: sma Get Plugin or Get Source (listmaps.sma - 597 views - 2.6 KB)
tm. is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 09-03-2010 , 12:43   Re: Dynamic arrays string sorting
Reply With Quote #2

Could you explain why you do that 2nd line :

PHP Code:
            ArrayPushString(g_MapsArrayszFileName);
            
ArraySetString(g_MapsArrayg_iTotalMaps++, szFileName); 
??


Also, i think that max mapname length is 32, without .bsp extension, so you should make a 36 sized array


About your problem, why don't you log everuy thing the plugin do at plugin start in a specific file, you could figure by yourself what is wrong ;)
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 09-03-2010 at 12:48.
ConnorMcLeod is offline
tm.
Member
Join Date: Apr 2010
Old 09-03-2010 , 12:59   Re: Dynamic arrays string sorting
Reply With Quote #3

Thanks for the reply.

From this:
Quote:
* The item must already exist, use ArrayPushArray to create a new item within the array.
I've wrongly understood that I need to use ArrayPushArray before I can use ArraySetString.
I thought ArrayPushArray it's some kind of initialization, that it doesn't actually sets the item in the array .
Also I did some debugging but didn't figure out a 'slimmer' way to do the sorting.

LE: Test it without
PHP Code:
ArraySetString(g_MapsArrayg_iTotalMaps++, szFileName); 
Doesn't work that way.

Last edited by tm.; 09-03-2010 at 13:09.
tm. is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 09-03-2010 , 15:11   Re: Dynamic arrays string sorting
Reply With Quote #4

Also, maps names are already sorted by default when reading directory, how are you trying to sort ?
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
tm.
Member
Join Date: Apr 2010
Old 09-03-2010 , 16:08   Re: Dynamic arrays string sorting
Reply With Quote #5

On win it does, on linux the list seems to be random, or listed by a criteria I don't know. I want it sorted alphabetically ascending. As I said, I've managed to do that with that code, but I was just wondering if it's a better way to do it.
tm. 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 08:57.


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