Jeremy,

Actually, if you read my message VERY carefully (I did some editing and didn't 
exactly read over it before I rushed off to work), I presented two seperate 
methods for solving the problem.

The first method is with "function pointers" (or God forbid, functors...).  The 
second method was with member functions.

def cast_code(self):
  """some function to cast spells or something"""

def cast_code2(self):
  """some other function to cast spells or something"""

class Skill:
  self.name=""
  self.mana=0
  self.cast_code=cast_code
#...

s=Skill()
s.cast() # Exec's cast_code

s=Skill()
s.cast_code=cast_code2
s.cast()

Function pointer method.  If you truly need an example of the function pointer 
syntax (to member functions... believe me this is an ugly mess and is one of 
the best reasons NOT to use C++ for something like this...), I'm sure I can dig 
one up in my "Archive".

The second method was the function method, and isn't the method that I'd 
recommend.  As far as overhead goes, you won't be incurring any additional 
overhead unless you're programming things in a silly way (like recursion or 
with excessive usage of virtual functions.  Even then virtual functions are a 
single dereference away as far as efficiency!).

Note that the 2nd method is probably the simplest method, though there might be 
some repeated code (and hence a larger compile size).  I doubt it'd cause 
anything more than memory bload to have each and every skill have the same 
functions.   Though another solution might be to use inheritance to inherit the 
function in ... but nheritance is another matter entirely. :-)

Regards,
Mark

Reply via email to