Game Engine Help

As my first Ruby endeavour, I have decided to make
a small text based RPG.

This is probably a huge undertaking for a noob.

I have made like, 3 or 4 classes so far.
This is the character generation stage, and for some reason,
it doesn’t like me. It won’t work. Well, I’ll
post my code so far(Yes, ChooseClass is incomplete.), and could someone
tell me what I have done wrong and how to make it better?

Here’s my code:

class Game_Start
attr_accessor :strength
attr_accessor :defense
attr_accessor :agility
attr_accessor :evasion
attr_accessor :hp
attr_accessor :mp
attr_accessor :max
attr_accessor :min
attr_accessor :name
def initialize
hp.max = 100
hp.min = 1
hp.name = ‘HP’
mp.max = 100
mp.min = 1
mp.name = ‘MP’
strength.max = 20
strength.min = 1
strength.name = ‘Strength’
defense.max = 20
defense.min = 1
defense.name = ‘Defense’
agility.max = 20
agility.min = 1
agility.name = ‘Agility’
evasion.max = 20
evasion.min = 1
evasion.name = ‘Evasion’
$hero_class = [‘Warrior’, ‘Mage’, ‘MageWarrior’]
end
end
#That defines all the normal abilities in the game. Soon, in version 2,
I will add special abilities.
class Roll < Game_Start
def initialize(ability)
maximum = ability.max - 1
roll = rand(maximum)
roll = roll + 1
print ability.name
print ': ’
print roll
puts ‘’
end
end
class RollAbilities < Game_Start
strength = Roll.new(strength)
defense = Roll.new(defense)
agility = Roll.new(agility)
evasion = Roll.new(evasion)
puts ‘Would you like to keep these stats?’
puts ‘y/n’
input = gets
if input == ‘y’
$strength = strength
$defense = defense
$agility = agility
$evasion = evasion
puts ‘-----’
ChooseName.new
else
RollAbilities.new
end
end
class ChooseName
def initialize
puts ‘Please Select your Name, by typing it in now.’
name = gets
if name == ‘’
puts ‘Sorry, that name is invalid’
else
print ‘Are you sure that ’
print name
print ’ is a good name?’
print ’ y/n ’
ans = gets
if ans == ‘y’
$name = name
ChooseClass.new
else
puts ‘Okay, choose again.’
puts ‘-----’
ChooseName.new
end
end
puts ‘Here is your information so far:’
puts 'Name: ’
puts $name
puts 'Strength: ’
puts $strength
puts 'Defense: ’
puts $defense
puts 'Agility: ’
puts $agility
puts 'Evasion: ’
puts $evasion
end
end
class ChooseClass < Game_Start
def initialize
puts ‘Please select a class to view information on.’
puts ‘Classes are:’
puts $hero_class
end
end


There it is.
As you may have guessed, it runs in the Ruby Console window.
Can anyone help me? I need help desperately.

I am new to Ruby so I am trying to learn all this stuff. I noticed in
some areas you have puts and in others you have print. . . are these the
same in Ruby?

Jeremy wrote:

I am new to Ruby so I am trying to learn all this stuff. I noticed in
some areas you have puts and in others you have print. . . are these the
same in Ruby?

No! When you use puts you will have a newline at the end of output.
print will simply print out without newline.

Example:

[hanez@phantom ~]$ irb
irb(main):001:0> puts 1
1
=> nil
irb(main):002:0> print 1
1=> nil
irb(main):003:0>

I’m a noob myself, but I’ll try to help out.

One thing I noticed that won’t affect much, except shorten your code, is
that you have this:

attr_accessor :strength
attr_accessor :defense
attr_accessor :agility

and so on, when you could shorten it to this:

attr_accessor :strength, :defense, :agility, etc

I can’t really think of much else, but then again, I’m pretty tired.

Good luck!

Caleb Boese wrote:

class Game_Start
attr_accessor :strength
attr_accessor :defense
attr_accessor :agility
attr_accessor :evasion
attr_accessor :hp
attr_accessor :mp
attr_accessor :max
attr_accessor :min
attr_accessor :name
def initialize
hp.max = 100
hp.min = 1
hp.name = ‘HP’
mp.max = 100
mp.min = 1
mp.name = ‘MP’
strength.max = 20
strength.min = 1
strength.name = ‘Strength’
defense.max = 20
defense.min = 1
defense.name = ‘Defense’
agility.max = 20
agility.min = 1
agility.name = ‘Agility’
evasion.max = 20
evasion.min = 1
evasion.name = ‘Evasion’
$hero_class = [‘Warrior’, ‘Mage’, ‘MageWarrior’]
end
end

Umm, I’m probably the least-qualified person here to help, but won’t the
thing say something like “method not defined - max” for hp, strength,
etc.? I’m probably wrong here, but I don’t think fixnums (it is a fixnum
object, right?) have a “max” property that can be changed. If I’m right,
though, you’ll probably have to put one in. Also, you may wish to put an
@ at the front of your hp, mp, strength, and other variables-- they are
instance variables, correct? If they’re class variables, though, you
just put two in front. I never use such things, though-- I can’t get my
head around them. Hope this helps.

—SoFaRo

PS: This may be nitpicky, but why make GameStart, Roll, ChooseName, and
ChooseClass objects instead of methods? Of course, as far as I can tell,
your y/n prompt would probably work better than the one I’m currently
struggling
with.