Error: unknown command
#1

Hey guys, I'm running a small code that sorts an array from lowest to highest, the problem is that I want to present the sorted array in a message box dialog after the sorting.
But for some reason, I get an "Error: unknown command" after typing the command, and it still sorts the array.
Another thing I noticed - I tried doing the sorting without the dialog, still "unknown command"
Anyone ?
PHP код:
if(!strcmp(cmdtext"/sortarray"))
    {
        new 
tmpstring[1024];
        for(new 
0<= sizeof(Array); j++)
        {
            for(new 
0sizeof(Array); i++)
            {
                if(Array[
i] > Array[i+1] && Array[i+1] < sizeof(Array))
                {
                    
tmp = Array[i];
                    Array[
i] = Array[i+1];
                    Array[
i+1] = tmp;
                }
            }
        }
        for(new 
0sizeof(Array); i++) format(stringsizeof(string), "%sArray[%d] = %d"stringi, Array[i]);
        
ShowPlayerDialog(playeridDIALOG_SORTDIALOG_STYLE_MSGBOX"Dialog Sorting"string"Close""");
         return 
1;
    } 
Reply
#2

It's most likely due to an index out of bounds error (accessing an index that is invalid).
Reply
#3

Your sorting method is quite bad man.Try with linear sorting
PHP код:
new i,j,tmp;
for(
i=0sizeof(Array)-1i++) 
        { 
            for(
j=i+1<sizeof(Array); j++) 
            { 
                if(Array[
i] > Array[j] ) 
                { 
                    
tmp = Array[i]; 
                    Array[
i] = Array[j]; 
                    Array[
j] = tmp
                } 
            } 
        } 
And yeah if you interested in knowing more sorts there is a lonely repo made by me for killing time (about array experimenting)https://github.com/Sreyas-Sreelal/Ar...ng-C-plus-plus
Note:its c++ but the algorithm can be applied universally
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)