2 registered members (AndrewAMD, NeoDumont),
761
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Save/Call function from Entity Skill
#476313
02/17/19 15:30
02/17/19 15:30
|
Joined: Oct 2008
Posts: 681 Germany
Ayumi
OP
User
|
OP
User
Joined: Oct 2008
Posts: 681
Germany
|
How to save/call an void/function pointer in a skill? This i tryed (in different ways):
void AnyFunc()
{
}
ENTITY* ent;
ent.skill1 = AnyFunc;
void main()
{
void ap;
ap = (void*)ent.skill1;
ap();
}
...Script error after call ap();
Last edited by Ayumi; 02/17/19 15:39.
|
|
|
Re: Save/Call function from Entity Skill
[Re: Superku]
#476320
02/17/19 18:33
02/17/19 18:33
|
Joined: Oct 2008
Posts: 681 Germany
Ayumi
OP
User
|
OP
User
Joined: Oct 2008
Posts: 681
Germany
|
Thanks for your answer. I try show more details: This doesn t work.
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();
}
|
|
|
Re: Save/Call function from Entity Skill
[Re: Ayumi]
#476323
02/17/19 19:54
02/17/19 19:54
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
It does work:
///////////////////////////////
#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.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Re: Save/Call function from Entity Skill
[Re: Ayumi]
#476325
02/17/19 22:20
02/17/19 22:20
|
Joined: Jul 2007
Posts: 619 Turkey, Izmir
Emre
User
|
User
Joined: Jul 2007
Posts: 619
Turkey, Izmir
|
Try this one.
///////////////////////////////
#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.
|
|
|
Re: Save/Call function from Entity Skill
[Re: Emre]
#476326
02/17/19 22:54
02/17/19 22:54
|
Joined: Oct 2008
Posts: 681 Germany
Ayumi
OP
User
|
OP
User
Joined: Oct 2008
Posts: 681
Germany
|
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.
Last edited by Ayumi; 02/17/19 22:59.
|
|
|
|