Gold to Grot

In my last post I attempted to use 'Class' as roles to weed out Grot characters that can never be used in the game as a PC. In the end I took the advice found in JT Smith's recent post and abandoned that idea.

While I want my program to be flexible enough to allow new races and classes to be added easily. What I do know that there will always be just six 'Ability' rolls, so why not just use them.

I will have to change a number of things in my 'Creator' class as I will drop my 6 Abilities them as simple Int 'Attributes' and I will try to use a class for each that has a 'roll' attribute for the values and on the 'BUILD' of each of these new classes I can see if the present score qualifies in one of the 'Character Classes' as that is all I really need to know.

I would also like to keep the same attribute names so I can still do $me->strength rater than $me->strength->roll. I can accomplish that I think with simple delegation and I will give that a try first.

So now I have my attributes like this

has 'strength' =>(
	is		=>'rw',
	isa		=>'RPG::ADD::Character::Creator::Strength',
	handles  =>['roll'],
	lazy_build  => 1,

in the 'Creator' class and my new 'Ability' classes are like this

package RPG::ADD::Character::Creator::Strength;
  use Moose;
 use RPG::ADD::Util::Types;

has 'roll' =>(
	is		=>'rw',
	isa		=>'AbilityRoll',

But unfortunately I get this

RPG::ADD::Character::Creator does not support builder method '_build_strength' for attribute 'strength' at C:\Dwimperl\perl\site\lib\Moose\ line 37

Opps. After rereading the the 'Delegation' pod again I saw my mistake. Seems this is used as a proxy for attributes and methods already in the class and I can't just expect a new class to magically appear as an attribute. I either have to supply an instance at creation time, instantiate it with a 'default=>' or have a builder sub for it.

Not where I wanted to go with this.

Every have one of those days:(


Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations