08302005 20:00
Posted by:
Arcygenical
Location:
Oakville, Ontario, Canada

Alright... Here I go,
I'm designing a custom battle system for a turn based RPGtype game, and have encountered a couple of problems along the way. I was just wondering if anyone could help me out a bit.
As I said above, my game employ's a turn based system, but I'm not too sure on how to go about generating the turn order. What I really need is a way to sort a 2 dimensional array by one of its columns... Well, say you have:
"Erika", 10
"Valin", 15
"Mellie",14
How could you get an array that is ordered like:
Valin
Mellie
Erika
Of course, there will be up to 10 characters in this list, thus I do need the code to be somewhat modular... Anyways, that's about it, so ANY help would be greatly appreciated :). Thanks guys,
Arcy

08302005 22:00
Posted by:
allnodcoms
Location:
hertfordshire (England)

Fastest way is QSort, but unfortunately you can't use it! You're using multidimensional arrays, so you need a custom routine. The thing to bare in mind is that you don't need to sort the array, just build another array with the same number of indices as the main one, then go through the main array and find the lowest value you are interested in. Put the 'index' of this numer in the new array, so if:
character[5, reaction_time]
is the lowest score you would store '5' in position zero of the new array.Then you go through again looking for the next lowest, and so on.
When you go to loop through the characters, the names would be (for example):
character[new_array[index], name] 'if you get that?
Basically you are building a reference array (much quicker) and using this to get at the values you want. Any problems just drop me a line...
Danny (nods)

10142005 19:09
Posted by:
Wil Hostman

There is also the progressive loop sort.
z = length of array A
For x = 1 to z
if A[x1][1] > A[x][1]
H0 = A[x1][0]
H1 = A[x1][1]
A[x1][0] = A[x][0]
A[x1][1] = A[x][1]
A[x][0] = H0
A[x][1] = H1
z=z2
if z < 0
z = 0
end if
end if
next x
the index reversion says if you moved one item back one, follow it. It's not the absolute fastest, but you can use it for any number of elements and dimensions (by expansion of the code).
I don't recall if the format
A[x1] = A[x]
works under TNT.
