09 Apr, 2013, Davenge wrote in the 1st comment:
Votes: 0
I need some help passing a method as a parameter. I did some google searching and the examples given were either confusing or I'm an idiot or a mix of both. So, I will explain the situation and what I need it to do and hopefully someone can just give me the code in my situation that I need and I can learn that way.

I'm writing code for a basic heal spell. However, it and all other spells can be affected by this thing called "glory". Glory will echo the spell cast to all others in the targets group. For example, the code looks something like this…
heal_char( ch, victim );
glory_echo( ??? );

void glory_echo( ??? )
CHAR_DATA *gvictim;

if( is_affected( ch, gsn_glory ) )
for( gvictim = victim->in_room->first_person; gvictim; gvictim = gvictim->next_in_room )
if( !is_same_group( victim, gvictim ) )
if( gvictim == victim )
method_passed( ch, gvictim ) – In this case it would be heal_char

Now, I get there are other ways that would require a lot more writing, and then rewriting every time I added a new spell, or I could rewrite the entire spell system to support this. However, this would be a convenient hack to make it work.

Thanks in advance, Davenge~~~
09 Apr, 2013, Tyche wrote in the 2nd comment:
Votes: 0
Function declaration:
void glory_echo(void (*spell_function)(CHAR_DATA *,CHAR_DATA *));
Call it.
09 Apr, 2013, Davion wrote in the 3rd comment:
Votes: 0
If you're using merc/ROM derivative or close too, you can just use SPELL_FUN. It's used as a parameter in a table for spells. You can just use it and pass it that way. If not, the basic idea is to declare a set of function with identical arguments.

The idea is you start with a typedef for your new function.
typedef void SPELLS_FUN ( CHAR_DATA *ch, CHAR_DATA *vict );

To use it later
void glory_echo( SPELLS_FUN *the_fun )
{ …
the_fun(ch, vict);


But ya… you most likely already have all this. Just look for SPELL_FUN…ninja'd :D
09 Apr, 2013, Davenge wrote in the 4th comment:
Votes: 0
rockin', Tyche, thanks man.
Random Picks