Call function with STRING or function array?

Posted By: Rasch

Call function with STRING or function array? - 01/11/11 23:26

hi

i have a problem as always laugh

I just want to know if it is possible to have function arrays. Cause i want to call function from a spell list or better id. I send an id and the correct spell function is started.

Instead of
Code:
Heal(caster, cast_target, random_add);



i want something like
Code:
spell_id(caster, cast_target, random_add);



Is it possible in any way?
Posted By: WretchedSid

Re: Call function with STRING or function array? - 01/11/11 23:32

What do you want to do?! Neither of your examples is an array of function pointers.
While basically there is no problem having a bunch of pointers in an array which points to functions (thats what you do when you call a function, you jump to another code address and continue execution from there), you seem to have no idea so you might want to stick with something else.
Posted By: Saturnus

Re: Call function with STRING or function array? - 01/11/11 23:33

Is this what you're looking for?
http://www.conitec.net/beta/engine_getscript.htm
Posted By: Rasch

Re: Call function with STRING or function array? - 01/11/11 23:46

yes it is. but itīs not working. What i mean is instead of writing Heal(...) i want to for example take a string that hold "Heal" inside and place that string before the (...)

STRING* spell_id = "Heal";

spell_id(...)

But that doesnt work.
Posted By: WretchedSid

Re: Call function with STRING or function array? - 01/11/11 23:55

Obviously it does not. Its a string, not a function wink
Look into saturnus link, it will help you.
Posted By: Rasch

Re: Call function with STRING or function array? - 01/12/11 00:04

I got it. Never done it before with function pointers. That was easy just didnt understand what exactly i have to write.

Thanks
Posted By: Rasch

Re: Call function with STRING or function array? - 01/12/11 10:28

Ok another problem. If iīm writing

engine_getscript("Heal");

The spell is found.

If i use a STRING that contains "Heal" itīs not finding anything. I want something like this. Maybe it has to be a char? But that also didnt work.

STRING* spell_type = "Heal";
engine_getscript(spell_type);
Posted By: MrGuest

Re: Call function with STRING or function array? - 01/12/11 10:53

STRING* spell_type = "Heal";
change to
STRING* spell_type = str_create("Heal");
Posted By: Rasch

Re: Call function with STRING or function array? - 01/12/11 13:51

Are you sure? I cant test it at the moment but if i use the first method its a string with content.

I think str_create would be for String Arrays like..

STRING* spell_type[3];
spell_type[0] = str_create("Heal");
spell_type[1] = str_create("Fire");
spell_type[2] = str_create("Ice");

But thats the same cause if i give out my string with error(spell_type) it says correctly Heal.

Maybe it needs another input in the brackets?

eedit: ok i got it

engine_getscript(_chr(spell_type));

made it laugh
© 2024 lite-C Forums