Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Question about sorting arrays

Author
Message
oDCo
20
Years of Service
User Offline
Joined: 11th May 2005
Location:
Posted: 13th Jul 2005 05:57
Hello all,

I'm trying to get a program to access the values in arrays in an order based on one of the array values.

Basically I want the values below to be printed in a different order to how they are in the array . . . when you see the code, what I'm saying will make more sense.



I want to have the following printed using the above array



I don't mind if there is a new array made which these values are placed into as I could then use the FOR NEXT command to print the values in the new order. For some reason though, I can't get my head around how to do this so any help would be greatly appreciated.

Cheers,

David
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 13th Jul 2005 07:32 Edited at: 13th Jul 2005 07:33
Here you go. Use one for next loop to count from 20 to 1 backwards (the step -1) and inside another for next loop to check each array number if it's equal to the backwards count. Hope this helps.



I'm curious though... what do you need this for?
oDCo
20
Years of Service
User Offline
Joined: 11th May 2005
Location:
Posted: 14th Jul 2005 04:40
Grog, you're a genius, thanks

As for why I need this . . . I'm putting together a little turn based RPG and I want to have the order in which characters and enemies take part in combat based on their initiative (which is represented by a number).

I couldn't get my head around a way of doing this, but thanks to your help I've now got it sussed. The code below shows exactly what I've done . . . the PRINT commands will be links to sub-routines to deal with the combat in my program, but this gives you an idea of what I've done with your code.

Thanks again for the help and once again this forum has proved itself to be invaluable

Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 14th Jul 2005 10:28
Thanks

Good looking code there too.
oDCo
20
Years of Service
User Offline
Joined: 11th May 2005
Location:
Posted: 15th Jul 2005 05:02
Quote: "Good looking code there too."


Thanks I was worried it wasn't very good and nearly didn't post it.

*note to self* Be more confident

Thanks again for the help . . . if we can just get this blasted heat out of the way, I might be able to concentrate long enough to implement it into my program

Login to post a reply

Server time is: 2025-05-22 22:34:49
Your offset time is: 2025-05-22 22:34:49