A
August0866
Hi All,
I am not a programmer, yet. I am trying ruby on for size, most things
fit ok, but Classes are puzzling me.
<code>
class Roll
def Roll(base,range)
@base=base
@range=range
@roll = base+random(range)
end
end
class Stats
def power
@power=Roll.new(10,8)
end
def speed
@speed=Roll.new(10,8)
end
def smarts
@smarts=Roll.new(10,8)
end
end
class Attribs < Stats
def acc
@acc=0.75*self.power+(self.speed/self.smarts)
end
def health
@health = self.power*(self.smarts/self.speed)
end
end
class Npc < Attribs
def name(name)
@name=name
end
end
joe=Npc.new
joe.name('Joe')
#puts joe.name.to_s+' = name'
puts joe.power.to_s+' = power'
puts joe.smarts.to_s+' = smarts'
puts joe.speed.to_s+' = speed'
puts joe.health.to_s+' = health'
puts joe.acc+' = acc'
puts joe
puts '======================='
puts 'Calculations'
puts 0.75*joe.power+(joe.speed/joe.smarts)
</code>
OK, so why is this broken?
I am not a programmer, yet. I am trying ruby on for size, most things
fit ok, but Classes are puzzling me.
<code>
class Roll
def Roll(base,range)
@base=base
@range=range
@roll = base+random(range)
end
end
class Stats
def power
@power=Roll.new(10,8)
end
def speed
@speed=Roll.new(10,8)
end
def smarts
@smarts=Roll.new(10,8)
end
end
class Attribs < Stats
def acc
@acc=0.75*self.power+(self.speed/self.smarts)
end
def health
@health = self.power*(self.smarts/self.speed)
end
end
class Npc < Attribs
def name(name)
@name=name
end
end
joe=Npc.new
joe.name('Joe')
#puts joe.name.to_s+' = name'
puts joe.power.to_s+' = power'
puts joe.smarts.to_s+' = smarts'
puts joe.speed.to_s+' = speed'
puts joe.health.to_s+' = health'
puts joe.acc+' = acc'
puts joe
puts '======================='
puts 'Calculations'
puts 0.75*joe.power+(joe.speed/joe.smarts)
</code>
OK, so why is this broken?