TNT Basic Forums > Programming Q&A
Battle System Question
< Last Thread     Next Thread >
Thread        Post A Reply

08-30-2005 20:00

Posted by:

Oakville, Ontario, Canada

Click Here to Email Arcygenical   Find more posts by Arcygenical

Alright... Here I go,

I'm designing a custom battle system for a turn based RPG-type 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

How could you get an array that is ordered like:


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,


08-30-2005 22:00

Posted by:

hertfordshire (England)

Click Here to Email allnodcoms   Find more posts by allnodcoms

Fastest way is QSort, but unfortunately you can't use it! You're using multi-dimensional 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)

10-14-2005 19:09

Posted by:
Wil Hostman

Find more posts by Wil Hostman

There is also the progressive loop sort.
z = length of array A

For x = 1 to z
if A[x-1][1] > A[x][1]
H0 = A[x-1][0]
H1 = A[x-1][1]
A[x-1][0] = A[x][0]
A[x-1][1] = A[x][1]
A[x][0] = H0
A[x][1] = H1
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[x-1] = A[x]

works under TNT.

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.