Game Development Reference
In-Depth Information
Victory! We have three more statements to go for this method. The next one uses the
ActorDamage
and
EnemyDamage
Vocabs. My copy-paste of part of the
Vocab
module (back on pages 4 and 5) is universally useful for what
we'll be doing here, so take a peek at the relevant variables.
ActorDamage = "%s took %s damage!"
EnemyDamage = "%s took %s damage!"
As you can see, both
ActorDamage
and
EnemyDamage
use the same sentence structure. The only thing that would
change is the origin of
@battler.name
. Incidentally, that particular
elsif
statement is fine. It requires no alterations.
The next
elsif
statement uses
ActorRecovery
and
EnemyRecovery
, which read as such:
ActorRecovery = %s recovered %s %s!"
EnemyRecovery = "%s recovered %s %s!"
Much like the previous case, both variables share the same sentence structure. Thus, they share the same textual
hiccup. Let's take the
ActorRecovery
sentence for example. The
sprintf
method passes
@battler.name
,
Vocab::hp
,
and
-hp_damage
, in that order. If Eric is the Actor in question, and the value of
-hp_damage
is 20, it would read like this.
Eric recovered HP 20.
Thankfully, that statement
is
as easily fixed as swapping the order in which the parameters are plugged into the
sentence, unlike the similar case back at the initial
if
statement. As the
else
statement is also correctly expressed,
here's the completely tweaked version of
hp_damage_text
:
class Game_ActionResult
#--------------------------------------------------------------------------
# * Get Text for HP Damage
#--------------------------------------------------------------------------
def hp_damage_text
if @hp_drain > 0
fmt = @battler.actor? ? Vocab::ActorDrain : Vocab::EnemyDrain
if fmt = Vocab::ActorDrain
sprintf(fmt, @battler.name, @hp_drain, Vocab::hp)
else
sprintf(fmt, @hp_drain, Vocab::hp, @battler.name)
end
elsif @hp_damage > 0
fmt = @battler.actor? ? Vocab::ActorDamage : Vocab::EnemyDamage
sprintf(fmt, @battler.name, @hp_damage)
elsif @hp_damage < 0
fmt = @battler.actor? ? Vocab::ActorRecovery : Vocab::EnemyRecovery
sprintf(fmt, @battler.name, -hp_damage, Vocab::hp)
else
fmt = @battler.actor? ? Vocab::ActorNoDamage : Vocab::EnemyNoDamage
sprintf(fmt, @battler.name)
end
end
■
Caution
Don't forget the class definition at the very top of your script page!
One down, two more to go!