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.

[XP] Stupid no method error...

Any assistance for this? I've been carving out my battle system and I'm doing skills now. But for some reason instead of calculating damage, the stupid program gives me a no method error, saying that there is no '+' method.

I fixed it once, but when I went back to allow healing, it suddenly decided it was going to flip out on me and start again -.-

Anyone able to help? The entirety of the skill code is below.

Code:
#--------------------------------------------------------------------------
# * Apply Skill Effects
# user : the one using skills (battler)
# skill : skill
#--------------------------------------------------------------------------
def skill_effect(user, skill)
# Clear critical flag
self.critical = false
if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
return false
end
# Clear effective flag
effective = false
# Set effective flag if common ID is effective
effective |= skill.common_event_id > 0
# Casting Chance - 1d10 - user.int / 4 is smaller than remaining Sanity
hit_result = ((rand(9) + 1) - [user.int / 4, 0].min < user.sp)
# If hit occurs
if hit_result == true
# Calculate Damage
self.damage = nil
for x in (1..skill.atk_f)
self.damage += rand(skill.power - 1) + 1
end
# Element correction
self.damage *= elements_correct(skill.element_set)
self.damage /= 100
# If damage value is strictly positive
if self.damage > 0
# Guard correction
if self.guarding?
self.damage /= 2
end
end
# If physical attack has power other than 0
if skill.power != 0 and skill.atk_f > 0
# State Removed by Shock
remove_states_shock
# Set to effective flag
effective = true
end
# Substract damage from HP
last_hp = self.hp
if skill.scope == 3 or skill.scope == 4
self.hp += self.damage
else
self.hp -= self.damage
end
effective |= self.hp != last_hp
# State change
@state_changed = false
effective |= states_plus(skill.plus_state_set)
effective |= states_minus(skill.minus_state_set)
# If power is 0
if skill.power == 0
# Set damage to an empty string
self.damage = ""
# If state is unchanged
unless @state_changed
# Set damage to "Miss"
self.damage = "Fail"
end
end
# If miss occurs
else
self.damage = nil
# Calculate Damage
for x in (1..skill.atk_f)
self.damage = rand(skill.power - 1) + 1
end
# Deal damage to user and Set damage to "Fail"
user.hp -= self.damage
self.damage = "Fail"
end
# If not in battle
unless $game_temp.in_battle
# Set damage to nil
self.damage = nil
end
# End Method
return effective
end
 
For future reference, please post more information about the error you're getting... for simplicity, you could just write exactly what the message says, or take a screenshot.
Also, proper indentation might seem like a hassle at the moment, but you'll be glad you learned to do it once you realize that it makes code easier to read, and errors easier to find.

Anyways, I looked through the code, and found something which will give you that error. The lines in question are these (starting at approximately line #20):
Code:
self.damage = nil
for x in (1..skill.atk_f)
  self.damage += rand(skill.power - 1) + 1
end
As you can see, you're setting the variable "damage" to nil, which is an instance of NilClass. Then, in the loop, you're treating "damage" as if it were a Numeric. Or rather, you're trying to access the "+" method of "damage". NilClass does not have this method, and thus you get an error. To get rid of the error, simply make sure to set "damage" to something which does have the "+" method.

In this case, I believe 0 is what you're looking for.
 
or another way might be to change it from this

Code:
self.damage = nil
for x in (1..skill.atk_f)
  self.damage += rand(skill.power - 1) + 1
end

to this

Code:
self.damage = false
for x in (1..skill.atk_f)
  self.damage += rand(skill.power - 1) + 1
end
 

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