Thanks for the reply, Mark. I look a look at the Python code you wrote
and did some more research. I'm aiming at having member pointers
instead of declaring all the different skill functions within the class
because of this:
class Skill
{
public:
string name;
int mana;
void (*Skill::cast_code)(CHAR_DATA *, char *) = NULL;
private:
void Skill::skill1_cast_code (CHAR_DATA *ch, char *argument)
{
whatever;
return;
}
void Skill::skill2_cast_code (CHAR_DATA *ch, char *argument)
{
whatever;
return;
}
...
}
And we'd assign each Skill's cast_code member pointer to an appropriate
class method on load:
Skill x;
x.cast_code = &skill1_cast_code;
(x.*cast_code)(ch, argument);
Unfortunately, as we approach ROM's number of skills (say 200), this
takes up considerable overhead having every Skill contain all the cast
methods for all Skills.
I think what I am looking for is a functor, as they are commonly
called. I'll unfortunately need to create each skill as an individual
class (frown) or alternatively encapsulate the Skill class to use the
relevant pointers.
If anyone cares, I can keep the list posted on my results.
-- Jeremy
Mark Roberts wrote:
<snip>
class Skill
{
public:
string name;
int mana;
...
SKILL_FUN *cast_code;
SKILL_FUN *pulse_code;
SKILL_FUN *upkeep_code;
SKILL_FUN *expire_code;
};
</snip>
Pointers, in Pythonese, to what I think you're trying to do... I'm
sure you can figure out the syntax needed. ;-)
def cast_code(self, args):
"""This is an external function to any number of skills that does
nothing!"""
class Skill:
self.name=""
self.mana=0
self.cast_code=cast_code
...
s=Skill()
s.cast() # Exec's cast_code
The error you're getting is because you don't have the appropriate
functions declared in the class:
class Skill
{
public:
string name;
int mana;
...
SKILL_FUN *cast_code;
SKILL_FUN *pulse_code;
SKILL_FUN *upkeep_code;
SKILL_FUN *expire_code; <-- These need to be actual function
declarations rather than function pointers
};
The way I suggested up top is probably what you're trying to do, but
in case its not, make those functions instead of function pointers, k?
Mark