arrays

Here you can post threads requesting help on the official POL Ultima Online Emulator Core 095. Note: Core 095 is no longer officially supported.
Post Reply
qrak
Grandmaster Poster
Posts: 198
Joined: Sun Feb 05, 2006 4:35 pm

arrays

Post by qrak »

Any ideas how to sort two dimension array? like

Code: Select all

table.append({integervalue, stringvalue});
table.sort();
I want my script to sort by integer values, how to do it?
Bytehawk
Apprentice Poster
Posts: 56
Joined: Fri Feb 03, 2006 2:25 am

Post by Bytehawk »

Taken from Siggy's String Function Include, v1.3

Code: Select all

// function SortMultiArrayByIndex(MultiArray, SubIndex)
// (Function added 26-Apr-2000 by Myrathi)
// This function will sort an array of arrays (or structures) by
// the contents of the sub-index provided. So, if you have an
// array (zCoords) of [x,y,z] structures, calling the function
// with 'fn(zCoords,2)' will sort by the second sub-index... that
// is, the 'y' member. Returns '0' if the SubIndex is invalid
// (only checks against the first index)

function SortMultiArrayByIndex(MultiArray, SubIndex)

  var ArrayLen:= Len (MultiArray);

  if (ArrayLen < 2)
    return MultiArray;
  endif

  if (SubIndex > len (MultiArray[1]))
    return 0;
  endif

  var i, k, f, s;

  for (i:= 1; i < ArrayLen; i:= i + 1)
    for (k:= i + 1; k <= ArrayLen; k:= k + 1)
      f:= MultiArray[i];
      s:= MultiArray[k];

      if (s[SubIndex] < f[SubIndex])
        MultiArray[i]:= s;
        MultiArray[k]:= f;
      endif
    endfor

    Sleepms(2);
  endfor

  return MultiArray;

endfunction
qrak
Grandmaster Poster
Posts: 198
Joined: Sun Feb 05, 2006 4:35 pm

Post by qrak »

Great Thx :)
Don't you think that should be hardcoded in pol96? :)
Post Reply