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.

Newcomers AppGameKit Corner / help with array sorting please

Author
Message
dandrews
4
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 11th Aug 2022 16:28
i have an array of guns with 0-4 types but under those types theres 5 different rarities. im trying to sort by gun.rarity.sort() somehow instead of gun.sort. is this possible ?
pavel_sv_1982
11
Years of Service
User Offline
Joined: 9th Apr 2013
Location: Russia
Posted: 11th Aug 2022 17:38
you can try this

a-type
b-sort
I know it's bad code, but that's how it works.
programming is a hobby, not a job.
P.S. in google and youtube - nikename pavelman- it is not me!
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 11th Aug 2022 18:07 Edited at: 11th Aug 2022 20:30
modifying the last GunChest example, Rarity added:


the pertinent parts:

...add instances of the gun type into a growing pool of choices to pick from with more instances of more-common guns increasing odds of more-common guns generated (weighting)

then, sorting the GunChest (10=Most-Common, 1=Most-Rare):

not thoroughly tested but it's all i have time for ATM and seems to work as intended:


NOTE: that's not the best bubble sort i expect. someone could probably make it more efficient (can i simply remove the Exit?).
i'll re-evaluate when i get a chance unless someone beats me to it
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 11th Aug 2022 20:25
i have a little time but still not to grips with better bubble sorting.

in the meantime, SortByDPS():

i probably should have used .CoolDown# vs .RateOfFire# from the get-go...

otherwise, no idea how you're building your guns, determining rarity (ie, this is not "Greater DPS = More Rare") so just making up some of this stuff in these examples to demonstrate functionality and hope these are helping
dandrews
4
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 12th Aug 2022 03:20 Edited at: 12th Aug 2022 05:21
I'm at work but what I did in the meantime was made another type to sort the information then reapplied it to the gunchest in the order I wanted. For the guns I have a gun, gun rarity, dmg and rps saved in the gunchest. Then whatever gunchest gun is selected that info is applied to gun_type to decide my player sprite animation frames and gun sounds
edit: also reading the help information on the swap() command i would have never known its use thank you that will save loads of code for me
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 15th Aug 2022 00:45
Bubble sort is easy to implement but one of, if not, the slowest algorithm. Quicksort is great, but for such a small data set an insertion sort might be faster. You haven't provided any code or details about the structure of your "guns", so I took a guess. It sorts an array (using insertion algorithm) within a TYPE.



Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda
Pixel-Perfect Collision

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

OriginalKronos
7
Years of Service
User Offline
Joined: 10th Nov 2017
Location:
Posted: 16th Aug 2022 21:04
According to documentation "When sorting types the first variable of the type will be used to compare elements."

so if you made the first variable a key you could just use array.Sort()?

For string sorts you need the leading zeros.

Steve Ancell
18
Years of Service
User Offline
Joined: 16th Feb 2006
Location: Brighton, East Sussex, UK
Posted: 19th Aug 2022 04:54 Edited at: 19th Aug 2022 05:37
I've just hammered this together, this will sort them alphabetically, will this do?

Steve Ancell
18
Years of Service
User Offline
Joined: 16th Feb 2006
Location: Brighton, East Sussex, UK
Posted: 19th Aug 2022 05:48 Edited at: 19th Aug 2022 05:54
I've modified it to sort by rarity, in case that's what you need instead.

Login to post a reply

Server time is: 2024-11-23 08:03:43
Your offset time is: 2024-11-23 08:03:43