Error: unknown command - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Error: unknown command (
/showthread.php?tid=618154)
Error: unknown command -
NeXoR - 01.10.2016
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 tmp, string[1024];
for(new j = 0; j <= sizeof(Array); j++)
{
for(new i = 0; i < sizeof(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 i = 0; i < sizeof(Array); i++) format(string, sizeof(string), "%sArray[%d] = %d", string, i, Array[i]);
ShowPlayerDialog(playerid, DIALOG_SORT, DIALOG_STYLE_MSGBOX, "Dialog Sorting", string, "Close", "");
return 1;
}
Re: Error: unknown command -
SickAttack - 01.10.2016
It's most likely due to an index out of bounds error (accessing an index that is invalid).
Re: Error: unknown command -
SyS - 02.10.2016
Your sorting method is quite bad man.Try with linear sorting
PHP код:
new i,j,tmp;
for(i=0; i < sizeof(Array)-1; i++)
{
for(j=i+1; j <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