Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Script to Auto-alphabetize armor upon entering equip menu?

I need a snippet of code that I can throw into my equipment menu script that would automatically alphabetize the Armor before it is drawn in the list upon entering the menu.

I am actually using the armor menu as a sort of in-game character phonebook, and I want the person name entries (each person is a piece of armor technically) to stay alphabetical in the list no matter in what order you encounter the characters in the game. Anybody have a simple, elegant solution for this I can just plug in?
 
Add this above the @data.push(nil) in Window_EquipItem

Code:
    @data.sort! {|x,y| y.name <=> x.name if x != nil and y != nil }

    @data.reverse

This is untested, but should work :D
 
Thanks for the help, guys! The second script called an error about icon.name or something in my script, (probably my script), but the first one worked.

This worked perfectly:

Code:
 @data.sort! {|x,y| x.name <=> y.name if x != nil and y != nil }

I didn't have to reverse the code once I switched the x.name and y.name.

A weird thing, though. The names are alphabetized now, A to Z. But one name, G. Rat (for 'Giant Rat') shows up at the end of the list. Why does the period after the G make it show up at the end?

Thanks again for your help, guys!
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top