# Game Engine Help

**URL:** <https://www.ruby-forum.com/t/game-engine-help/55961>\
**Category:** Ruby-Forum\
**Created:** [March 26, 2006, 7:49am UTC](https://www.ruby-forum.com/t/game-engine-help/55961 "2006-03-26T07:49:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![caleb-boese](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3e96dc/32.png) [@caleb-boese](https://www.ruby-forum.com/u/caleb-boese)\
**Post date:** [March 26, 2006, 7:49am UTC](https://www.ruby-forum.com/t/game-engine-help/55961/1 "2006-03-26T07:49:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![caleb-boese](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3e96dc/32.png) [@caleb-boese](https://www.ruby-forum.com/u/caleb-boese)\
**Post date:** [July 12, 2006, 5:23am UTC](https://www.ruby-forum.com/t/game-engine-help/55961/2 "2006-07-12T05:23:51Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![caleb-boese](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3e96dc/32.png) [@caleb-boese](https://www.ruby-forum.com/u/caleb-boese)\
**Post date:** [July 15, 2006, 3:13am UTC](https://www.ruby-forum.com/t/game-engine-help/55961/3 "2006-07-15T03:13:22Z")

</div>

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\>

---

<div class="post-metadata">

**Author:** ![caleb-boese](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3e96dc/32.png) [@caleb-boese](https://www.ruby-forum.com/u/caleb-boese)\
**Post date:** [August 16, 2006, 2:35am UTC](https://www.ruby-forum.com/t/game-engine-help/55961/4 "2006-08-16T02:35:00Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![caleb-boese](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/3e96dc/32.png) [@caleb-boese](https://www.ruby-forum.com/u/caleb-boese)\
**Post date:** [September 5, 2006, 11:43pm UTC](https://www.ruby-forum.com/t/game-engine-help/55961/5 "2006-09-05T23:43:51Z")

</div>

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.
