ruby - ArgumentError `initialize': wrong number of arguments(8 for 0) -


so i'm new ruby , i'm trying learn more converting python script i'm working on ruby. however, i'm running annoying problem. every time try run following code, error:

player.rb:81:in initialize': wrong number of arguments(8 0) (argumenterror) player.rb:81:innew' player.rb:81:in `'

i'm positive there 8 arguments in initialize method, , have checked spelling many times over. can't seem figure out why interpreter doesn't believe constructor doesn't have arguments. inform me going wrong below?

class player     def determinelevel         @xp_req4lvl = [0, 1000, 2250, 3750, 5500, 7500, 10000, 13000, 16500, 20500, 26000, 32000, 39000,47000,57000,69000,83000,99000,119000,143000,175000,210000,255000,310000,375000,450000,550000,675000,825000,1000000]         if xp <= 1000             @level = 1             return         end         i=0         while < xp_req4lvl.length             if xp > xp_req4lvl[i]                 i+=1             elsif xp == xp_req4lvl[i]                 @level = i+1                 return             else                 @level =                 return         end         ml = xp_req4lvl.length         raise levelingerror.new(ml), "level high!", caller         return     end      def initialize(personalinfo, training, race, chclass, feats, stuff, abilities, xp)         @str, @con, @dex, @int, @wis, @cha = abilities         @trainedskills = training         @characterclass = chclass         @feats = feats         @race = race         #for featx in self.race["racialfeats"]:         #    self.feats.append(featx)         @equipment = stuff         @background = personalinfo         @xp =xp         @actionpoints = 1         @equippedarmor = nil         @equippedshield = nil         @armorproficiencies = []         @shieldproficiencies = []         @untrainedarmorequipped = false         @untrainedshieldequipped = false         @level = 0         self.determinelevel         rescue levelingerror => e             puts "character on maximum level of " + e.get_max_lvl.to_s             @level = 30         end         #self.calculateabilityscores         #self.calculateabilitymods         #self.calculatehp         #self.determineproficiencies          #@fortitudesave = 10+(@level/2)         #@reflexsave = 10+(@level/2)         #@willsave = 10+(@level/2)         #puts @level.to_s          @healingsurgesused = 0     end      public     def get_level         return @level     end       end  class levelingerror < runtimeerror     attr :maxlvl      def initialize(ml)         @maxlvl = ml     end      def get_max_lvl()         return @maxlvl     end end  if __file__ == $0     j = player.new("0", "1", "2", "3", "4", "5", "[10,10,10,10,10,10]", "1250")     puts j.get_level.to_s end 

you missed 1 end keyword here:

while < xp_req4lvl.length             if xp > xp_req4lvl[i]                 i+=1             elsif xp == xp_req4lvl[i]                 @level = i+1                 return             else                 @level =                 return         end # !> mismatched indentations @ 'end' 'while' 

if put 1 more end here,you wouldn't error.but another- syntax error, unexpected keyword_end, expecting end-of-input due below:

def initialize(personalinfo, training, race, chclass, feats, stuff, abilities, xp)         @str, @con, @dex, @int, @wis, @cha = abilities         @trainedskills = training         @characterclass = chclass         @feats = feats         @race = race         #for featx in self.race["racialfeats"]:         #    self.feats.append(featx)         @equipment = stuff         @background = personalinfo         @xp =xp         @actionpoints = 1         @equippedarmor = nil         @equippedshield = nil         @armorproficiencies = []         @shieldproficiencies = []         @untrainedarmorequipped = false         @untrainedshieldequipped = false         @level = 0         self.determinelevel         rescue levelingerror => e             puts "character on maximum level of " + e.get_max_lvl.to_s             @level = 30         end # !> mismatched indentations @ 'end' 'def' 

you need follow below:

def method_name(..)   begin    # code   rescue    # codee   end end 

but don't use begin..rescue inside #initialize method.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -