Save/Call function from Entity Skill

Posted By: Ayumi

Save/Call function from Entity Skill - 02/17/19 15:30

How to save/call an void/function pointer in a skill?

This i tryed (in different ways):

Code:
void AnyFunc()
{
}

ENTITY* ent;
ent.skill1 = AnyFunc;

void main()
{
   void ap;
   ap = (void*)ent.skill1;
   ap();
}




...Script error after call ap();
Posted By: Superku

Re: Save/Call function from Entity Skill - 02/17/19 16:11

Seems to work for me:

Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////

int AnyFunc(int x)
{
	printf("Error Code %d", x);
}

void main()
{
	fps_max = 60;
	level_load(NULL);
	ENTITY* ent = ent_create(CUBE_MDL, nullvector, NULL);
	ent.skill1 = AnyFunc;
	
	int ap(int);
	ap = ent.skill1;
	ap(5);
}

Posted By: Ayumi

Re: Save/Call function from Entity Skill - 02/17/19 18:33

Thanks for your answer.

I try show more details:
This doesn t work.

Code:
void Go()
{
}

action Fly()
{	
   set (my, PASSABLE);
   my.skill15 = Go;
}

void RunAsync()
{
   	ENTITY* ent;
	you = ent_next(NULL);
 	while (you) 
	{ 
		if(you.string1 != NULL)
		{
			if(str_cmpi(you.string1,"vogel"))
			{	
				ent= you;
				break;
			}
		}
			 
 		you = ent_next(you); 
 	}

	void act();
	act = ent.skill15;
		
	act();
}

Posted By: txesmi

Re: Save/Call function from Entity Skill - 02/17/19 19:53

If the 'ent' pointer is filled, it should work. There is nothing wrong. Did Superkus example work for you?
Posted By: Superku

Re: Save/Call function from Entity Skill - 02/17/19 19:54

It does work:
Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////

void Go()
{
	error("hey!");
}

action Fly()
{	
	set (my, PASSABLE);
	my.skill15 = Go;
}

void main()
{
	fps_max = 60;
	level_load(NULL);
	ent_create(CUBE_MDL, nullvector, Fly);
	
	ENTITY* ent = NULL;
	you = ent_next(NULL);
	while (you) 
	{ 
		if(you)
		{
			ent= you;
			break;
		}
		
		you = ent_next(you); 
	}

	if(ent)
	{
		void act();
		act = ent.skill15;
		act();
	}
}



Probably your ent is undefined as you don't set it to NULL and don't check if the while(you) search has been successful.
Posted By: Ayumi

Re: Save/Call function from Entity Skill - 02/17/19 21:27

@txesmi
No, it also doesn t work for me (Scriptcrash in...)

@Superku
Same Error
Posted By: Emre

Re: Save/Call function from Entity Skill - 02/17/19 22:20

Try this one.

Code:
///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////

void Go()
{
	error("hey!");
}

action Fly()
{	
	set (my, PASSABLE);
	my.skill15 = (void*)Go;
}

void main()
{
	fps_max = 60;
	level_load(NULL);
	ent_create(CUBE_MDL, nullvector, Fly);
	
	ENTITY* ent = NULL;
	you = ent_next(NULL);
	while (you) 
	{ 
		if(you)
		{
			ent= you;
			break;
		}
		
		you = ent_next(you); 
	}

	if(ent)
	{
		void act();
	
		act = (void*)ent.skill15;
		act();
	}
}



i think you are using A7? because felix's code work with A8.
Posted By: Ayumi

Re: Save/Call function from Entity Skill - 02/17/19 22:54

Ty Emre, this example works now. Yes i am still using A7.
(But this doesn t fix my error).

EDIT: Fixed, i have to wait for init action.
Posted By: Emre

Re: Save/Call function from Entity Skill - 02/18/19 09:25

i'm glad the problem is solved. laugh
© 2024 lite-C Forums