Game Development Reference
In-Depth Information
Dissecting the hp_damage_text Method
Although the larger parts of the method may look like alphabet soup at the moment, we can deduce the four action
results handled by this method, based on the code expressions.
if statement displays a message when the attacker uses a skill that drains HP. A
draining attack heals the user for the same amount of HP that it deals to its target.
The initial
elsif statement is called when the attacker uses a skill that does HP damage.
The first
elsif statement is relevant when the character uses a skill that heals HP.
The second
else statement is used for the niche case in which the attacker uses a skill that does no
damage to its target.
The
With that established, let's dissect the first statement. It is two lines long and says the following:
fmt = @battler.actor? ? Vocab::ActorDrain : Vocab::EnemyDrain
sprintf(fmt, @battler.name, Vocab::hp, @hp_drain)
Before you start working on this section, don't forget to insert a new page in Materials at the script editor and
copy-paste the relevant methods as we require them. Direct alteration of code should always be avoided, if possible.
Note
Our variable assignment in the first line ( fmt ) is a perfect example of a local variable. As its name implies, a
local variable is only used wherever it is called. Thus, whatever is plugged into fmt is used only for this particular
statement and then scrapped. @battler.actor? is an instance variable that returns true if the battler is an Actor. If he/
she is an enemy, it will return false. If @battler.actor? is true, the ActorDrain text will be displayed; otherwise, the
EnemyDrain text will be displayed. The second line uses a special method called sprintf . RMVXA's help file has a very
useful write-up on the method. In layman's terms, you can use sprintf to fill in a predetermined sentence of text.
Let's go to the Vocab module and find ActorDrain . You'll find it along with several other terms, so here are lines 51
through 67 of the Vocab module:
# Results for Actions on Actors
ActorDamage = "%s took %s damage!"
ActorRecovery = "%s recovered %s %s!"
ActorGain = "%s gained %s %s!"
ActorLoss = "%s lost %s %s!"
ActorDrain = "%s was drained of %s %s!"
ActorNoDamage = "%s took no damage!"
ActorNoHit = "Miss! %s took no damage!"
# Results for Actions on Enemies
EnemyDamage = "%s took %s damage!"
EnemyRecovery = "%s recovered %s %s!"
EnemyGain = "%s gained %s %s!"
EnemyLoss = "%s lost %s %s!"
EnemyDrain = "Drained %s %s from %s!"
EnemyNoDamage = "%s took no damage!"
EnemyNoHit = "Missed! %s took no damage!"
 
 
Search WWH ::




Custom Search