RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[VX] Simple Skill Alphabetical Sort

0 Members and 1 Guest are viewing this topic.

*
Rep:
Level 82
GIAW 14: 1st Place (Easy Mode)2013 Project of the Year2013 Best RPG Maker User (Programming)2013 Most Promising ProjectParticipant - GIAW 11Bronze - GIAW 10
The code I have actually works, but I was wondering if there was a way to dump the sorted information back into the @actor.skill so I could just alias refresh instead of overwriting the whole thing? @actor doesn't seem to take kindly to any array, hash or string methods (.clear, etc) that I've tried so I'm not sure how to re-insert the sorted skill information.

Code: [Select]
class Window_Skill < Window_Selectable
  def refresh
    @data = []
    @data_sorted = @actor.skills.sort { |a,b| a.name.downcase <=> b.name.downcase }
   
    for skill in @data_sorted
      @data.push(skill)
      if skill.id == @actor.last_skill_id
        self.index = @data.size - 1
      end
    end
    @item_max = @data.size
    create_contents
    for i in 0...@item_max
      draw_item(i)
    end
  end
end

UPDATED 05-29-14


IS YOUR PROJECT OPTIMIZED?
UPDATED 07/04/15 - v2.5

RPG MAKER TOOLBOX
UPDATED 07/04/15 - v1.5

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
Well, you could alias the skills method in Game_Actor and do the sort there before returning it.

Of course, you could also do the sorting inside the learn_skill method of Game_Actor. That is how they do it in the default scripts and it's a little smarter since it means you aren't running a rather inefficient sort method every time you call the skills method. There is a possibility someone would have written a script which bypasses the learn_skill method for whatever reason and if so, that would effectually render your script unfunctional, but I think that would be a small risk.

Both ways, of course, would affect it everywhere skills is used though, so it may cause some incompatibilities with other scripts if they do weird things expecting skills to be sorted by ID.
« Last Edit: June 13, 2011, 12:57:38 AM by modern algebra »

*
Rep:
Level 82
GIAW 14: 1st Place (Easy Mode)2013 Project of the Year2013 Best RPG Maker User (Programming)2013 Most Promising ProjectParticipant - GIAW 11Bronze - GIAW 10
Yeah, I tried that as well and I found out that it was a Bad ThingĀ©. If I assign skill 1 through 10 to one actor and 11 through 20 to another actor then sort it using the skills method in Game_Actor, the first actor might have skills 1,5-7,17,20 depending on the name of the skill. So I'd have to go and update the new positions within the skills array for each actor. Meh.

Ah well ... the code works the way it is, I'm just trying to find ways to be more efficient.

EDIT: Hmm, I'll fiddle with the learn_skill and see what I can come up with.

UPDATED 05-29-14


IS YOUR PROJECT OPTIMIZED?
UPDATED 07/04/15 - v2.5

RPG MAKER TOOLBOX
UPDATED 07/04/15 - v1.5

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
I don't understand what you mean by that. If the first actor only gets skills 1 through 10, then alphabetically sorting them isn't going to give him skills 17 & 20. I also don't get why this would necessitate updating the positions with other actors. Already, the same skills will be in different positions in each actor's arrays depending on what skills they have. So, for instance, if Actor 1 has skills 5 & 7 and Actor 2 has skills 2, 3, & 5, then skill 5 will be in the 0 position for Actor 1 and in the 2 position for Actor 2. That doesn't cause any problems.

Also, it's not really any more efficient to alias and not redefine. It's actually (slightly) less efficient. The reason you would want to alias is more for compatibility reasons, as otherwise redefining the draw_item method could easily conflict with other custom skill scene scripts.
« Last Edit: June 13, 2011, 01:14:14 AM by modern algebra »

*
Rep:
Level 82
GIAW 14: 1st Place (Easy Mode)2013 Project of the Year2013 Best RPG Maker User (Programming)2013 Most Promising ProjectParticipant - GIAW 11Bronze - GIAW 10
Alright, I see what I did wrong. I was destructively sorting $data_skills which was re-sorting all of the skills and generally mucking things up. Sorting the result within the skills method in Game_Actor works just fine. I think I did it the first way because I could get away with aliasing then, since it was at the top ... of course then everything else was wrecked, but hey!

UPDATED 05-29-14


IS YOUR PROJECT OPTIMIZED?
UPDATED 07/04/15 - v2.5

RPG MAKER TOOLBOX
UPDATED 07/04/15 - v1.5

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Veteran2011 Favourite Staff Member2011 Most Mature Member2011 Best RPG Maker User (Scripting)2011 Best Use of Avatar and Signature Space2010 Most Mature Member2010 Favourite Staff Member
An alias would certainly be available by doing it at the bottom too. All you would need to do is:

Code: [Select]
  alias exhyd_alphsort_skills_5th2 skills
  def skills (*args)
    s =  exhyd_alphsort_skills_5th2 (*args)
    return (s.sort { |a,b| a.name.downcase <=> b.name.downcase })
  end
end

*
Rep:
Level 82
GIAW 14: 1st Place (Easy Mode)2013 Project of the Year2013 Best RPG Maker User (Programming)2013 Most Promising ProjectParticipant - GIAW 11Bronze - GIAW 10
Ooh, I see now. That's pretty neat ... I had it in my head that changes needed to be at the top before the original method was run. That opens up some more avenues to take on other scripts. Thanks for pointing that out!

UPDATED 05-29-14


IS YOUR PROJECT OPTIMIZED?
UPDATED 07/04/15 - v2.5

RPG MAKER TOOLBOX
UPDATED 07/04/15 - v1.5