Hey all!
So I'm currently looking at the BattleManager module in VX Ace and I've come across a version of the .sort! command that has a block with two variable designations (not sure if that's the right terminology sorry) within it.
You can see it in the last line here:
So, after reading the section in the Help Window about this, I THINK I've got an understanding of it but that understanding also gives rise to more questions if it's true... so I figured I'd just hop on here and see if anyone could help clear this up for me 🙂.
=====================================================================================
The Questions
(These questions are treated as case questions, as I'm not entirely sure which case is actually true and they can't all be true, so if I'm right about one of the cases then please feel free to just answer that case's questions and ignore the others)
Is it the case that:
This line assigns both the designation "a" AND "b" to EACH item within the Array?
-
If that's the case, then is "b.speed - a.speed" the same as "battler speed - action speed" ?
If that's true, then how is it assigning b the value of battler speed and how is it assigning a the value of action speed?
-
Or is it the case that:
This line assigns designation "a" to the first item in the Array and then designation "b" to the second item in the Array?
Repeating this for items "3 and 4" and "5 and 6" and so on and so forth?
-
If that's the case, then is it determining action order based on the speed value the battler has - the speed value the next battler has and so on and so forth until each battler's speed has been compared to the others'?
-
Or is it the case that:
This line works completely differently to these two possible understandings of it and I've been looking at this all wrong?
--
Thanks for any help.
Sorry for the nooby questions, but we all gotta learn sometime right?
So I'm currently looking at the BattleManager module in VX Ace and I've come across a version of the .sort! command that has a block with two variable designations (not sure if that's the right terminology sorry) within it.
You can see it in the last line here:
Ruby:
#--------------------------------------------------------------------------
# * Create Action Order
#--------------------------------------------------------------------------
def self.make_action_orders
@action_battlers = []
@action_battlers += $game_party.members unless @surprise
@action_battlers += $game_troop.members unless @preemptive
@action_battlers.each {|battler| battler.make_speed }
@action_battlers.sort! {|a,b| b.speed - a.speed } # <-- This line here
end
So, after reading the section in the Help Window about this, I THINK I've got an understanding of it but that understanding also gives rise to more questions if it's true... so I figured I'd just hop on here and see if anyone could help clear this up for me 🙂.
=====================================================================================
The Questions
(These questions are treated as case questions, as I'm not entirely sure which case is actually true and they can't all be true, so if I'm right about one of the cases then please feel free to just answer that case's questions and ignore the others)
Is it the case that:
This line assigns both the designation "a" AND "b" to EACH item within the Array?
-
If that's the case, then is "b.speed - a.speed" the same as "battler speed - action speed" ?
If that's true, then how is it assigning b the value of battler speed and how is it assigning a the value of action speed?
-
Or is it the case that:
This line assigns designation "a" to the first item in the Array and then designation "b" to the second item in the Array?
Repeating this for items "3 and 4" and "5 and 6" and so on and so forth?
-
If that's the case, then is it determining action order based on the speed value the battler has - the speed value the next battler has and so on and so forth until each battler's speed has been compared to the others'?
-
Or is it the case that:
This line works completely differently to these two possible understandings of it and I've been looking at this all wrong?
--
Thanks for any help.
Sorry for the nooby questions, but we all gotta learn sometime right?