|
1 registered members (AndrewAMD),
599
guests, and 3
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Entity Action with parameters
#322327
05/06/10 04:52
05/06/10 04:52
|
Joined: Oct 2008
Posts: 513
Carlos3DGS
OP
User
|
OP
User
Joined: Oct 2008
Posts: 513
|
Im not sure if this is possible... all the examples of action within ent_create i have found dont even have brackets() Is it possible for an action to have parameters? Something like this:
EntityPointer = ent_createlocal("Car.mdl",Position,Action_With_Parameters(PointerParameter,IntParameter));
If it is possible... Would that be the correct way of doing it? EDIT: I found this in the manual, Actions are another special kind of functions. They don't have parameters and don't return a value, but will appear in the action pop-up list in WED's entity property panel. So actions can be assigned to entities through WED, and are automatically executed after level loading. Action names are limited to 20 characters. Besides that, there is no difference between functions and actions. it seems that it is not possible to pass parameters to an action. If it is not possible... Does anyone know a workaround for my problem so an entity function can work with parameters?
Last edited by Carlos3DGS; 05/06/10 05:12.
|
|
|
Re: Entity Action with parameters
[Re: Carlos3DGS]
#322332
05/06/10 07:02
05/06/10 07:02
|
Joined: Feb 2005
Posts: 3,687 Hessen, Germany
Tempelbauer
Expert
|
Expert
Joined: Feb 2005
Posts: 3,687
Hessen, Germany
|
Does anyone know a workaround for my problem so an entity function can work with parameters?
yes. you can use the skills (entity.skill1, entity.skill2, ...) of an entity. this are parameters that can be used (for healthpoints for example). you could assign them after creation. if you need to wait until all params are set, you could use a while-loop that blocks the execution of the action until the params are passed. you can use these skill-parameters for passing integers or pointers of any struct. take a look in the manual for further information: http://www.conitec.net/beta/aentity-skill.htmhope it helps
|
|
|
Re: Entity Action with parameters
[Re: Tempelbauer]
#322357
05/06/10 10:53
05/06/10 10:53
|
Joined: Oct 2008
Posts: 513
Carlos3DGS
OP
User
|
OP
User
Joined: Oct 2008
Posts: 513
|
Lets see if I understood this right... Entity skills can hold pointers to other entities? So would this code be correct? EXAMPLE:
void Prepare_Entity(ENTITY*Created, ENTITY* PassedPointer, int PassedInt) //function called to pass parameters to entity
{
Created.Skill1=PassedPointer; //passing a pointer to the new entity
Created.skill2=PassedInt; //passing an int to the new entity
set(Created,FLAG1); //tell the entity its parameters are loaded
}
action Entity_Action()
{
while(1)
{
if(my.flag1!=0) //waits until flag 1 is set to know parameters have been passed to my skills
{
...
Do something with my awesome skill1 & skill2 that cointain a pointer to awesomeness and an awesome int lol;
...
}
wait(1);
}
}
void main()
{
ENTITY* NewEntity;
ENTITY* ImportantEntity;
int AwesomeInt;
...
NewEntity=ent_create("Car.mdl",nullvector,Entity_Action); //create entity
Prepare_Entity(NewEntity,ImportantEntity,AwesomeInt); //pass pointer and parameters to entity
...
}
If I understood you correctly and that code would achieve what I need it would be great news! A nice fix for my problem to be able to pass parameters to action functions with a clean workaround.
|
|
|
Re: Entity Action with parameters
[Re: Superku]
#322370
05/06/10 14:20
05/06/10 14:20
|
Joined: Oct 2008
Posts: 513
Carlos3DGS
OP
User
|
OP
User
Joined: Oct 2008
Posts: 513
|
Thankyou very much for your help  So I set the pointer into the skill using my.skill1 = handle(you); but how do I retrieve the pointer from skill in the action function? EDIT: Sorry for posting before searching "handle" in the manual For anyone else searching this thread in the future I found this: EXAMPLE if(entity) { my.skill48 = handle(entity); // store entity pointer } you = ptr_for_handle(my.skill48); // restore YOU;
Last edited by Carlos3DGS; 05/06/10 14:24.
|
|
|
Re: Entity Action with parameters
[Re: Carlos3DGS]
#322375
05/06/10 15:02
05/06/10 15:02
|
Joined: Oct 2008
Posts: 513
Carlos3DGS
OP
User
|
OP
User
Joined: Oct 2008
Posts: 513
|
I will risk testing your patience with one more question... Can I create an array of entities like this? ENTITY* List[4];
for(x=0;x<=3;x++) { List[x]=ent_create("Car.mdl",position,Action_Car); } And access the pointers directly like this? for(x=0;x<=3;x++) { List[x].skill1=x; } Is that possible? Would that method work?
|
|
|
Re: Entity Action with parameters
[Re: Lukas]
#322381
05/06/10 15:40
05/06/10 15:40
|
Joined: Aug 2007
Posts: 1,922 Schweiz
Widi
Serious User
|
Serious User
Joined: Aug 2007
Posts: 1,922
Schweiz
|
Yes, you can store Pointers directly without handle (a Pointer is nothing else a number). But if you want save and load your Game then this Pointers are no more the same. If you use handle and ptr_for_handle then you can save / load without problems, the handle is always the same.
Last edited by Widi; 05/06/10 15:46.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|