Local Pointer !

Posted By: mEnTaL

Local Pointer ! - 10/09/10 12:45

How can I create an ENTITY pointer which must be LOCAL for a certain entity. I need this for my AI - every NPC has a target1 ponter which must lead to a detected enemy.
Here is the code:

Code:
action ally()
{
ENTITY*target1;
if (my.status==attacking) 
{................}
........
my.event=detect_target;
}

function detect_target ()
{
	 if (event_type == EVENT_DETECT) 
  {
  	if (you.skill2==1)  // enemy detected
  	{
     my.status=attacking; target1=you;       }
   }
}



But the functions just can't recognize the pointer because it is local.

Any ideas how to make this little pointer local BUT recognized by the other functions?
Posted By: Quad

Re: Local Pointer ! - 10/09/10 13:21

use a skill instead.
Posted By: mEnTaL

Re: Local Pointer ! - 10/09/10 13:49

But the skill can't be used as a pointer.

my.skill15=you;
my.skill15.x=36;

and the engine says : " 'x' is not a member of a function "
I need I pointer local for the entity, but recognized by the other functions.
Posted By: jane

Re: Local Pointer ! - 10/09/10 14:04

define the "ENTITY*target1;" outside of the action,

in the enemy-action put in "target1=my;"

Posted By: mEnTaL

Re: Local Pointer ! - 10/09/10 14:17

If i put ENTITY*target1; outside the action then it will be a global entity and that means all my allies will shoot at the same target. My idea is to make every ally to have its own target1 entity and shoot at it.

Other ideas?
Posted By: jane

Re: Local Pointer ! - 10/09/10 14:49

try "ENTITY* target1 = you;"

other

"STRING* target1;"

other

"STRING* target1 = you;"
Posted By: MasterQ32

Re: Local Pointer ! - 10/09/10 15:12

you can use a handle:
Code:
action ally()
{
ENTITY*target1;
if (my.status==attacking) 
{................}
........
my.event=detect_target;
my.skill99 = handle(target1);
}

function detect_target ()
{
ENTITY* target1 = ptr_for_handle(my.skill99);
	 if (event_type == EVENT_DETECT) 
  {
  	if (you.skill2==1)  // enemy detected
  	{
     my.status=attacking; 
target1=you;      
 }
   }
my.skill99 = handle(target1);
}


Posted By: Saturnus

Re: Local Pointer ! - 10/09/10 15:25

You can also do it like that:

my.skill15 = you;
((ENTITY*)my.skill15).x = 36;

But using a handle is safer.
Posted By: Superku

Re: Local Pointer ! - 10/09/10 15:31

The entity-struct already has an entity-pointer, called my.parent.
Posted By: mEnTaL

Re: Local Pointer ! - 10/10/10 14:23

@Richi007 I tried your way, but when the event detect_target() is executed the engine crashes ("Don't send" error). There are no syntax errors, but maybe grammatic?

The others - Maybe I get something from your ideas, but can you give me a code example for my case, cuz I'm still not so skillful programmer.
Posted By: Superku

Re: Local Pointer ! - 10/10/10 14:52

action ally()
{
if (my.status==attacking)
{................}
........
my.event=detect_target;
}

function detect_target ()
{
if (event_type == EVENT_DETECT)
{
if (you.skill2==1) // enemy detected
{
my.status=attacking;
my.parent = you;
}
}
}
Posted By: jane

Re: Local Pointer ! - 10/10/10 15:16

you can test this (no errors ... but work ???):

action ally()
{
if (my.status==attacking)
{................}
........
my.event=detect_target;
}

function detect_target ()
{
ENTITY*target1;
if (event_type == EVENT_DETECT)
{
if (you.skill2==1) // enemy detected
{
my.status=attacking; target1=you; }
}
}
Posted By: Superku

Re: Local Pointer ! - 10/10/10 15:18

I'm sorry jane, but that's senseless because you cannot access the pointer from outside the event function.
Posted By: jane

Re: Local Pointer ! - 10/10/10 15:51

@Suprku

its right, the pointer is only in the event function useable.

its a way, give: ally 1 the skill5 = 1; ally 2 the skill5 = 2; ...

function detect_target ()
{
if (event_type == EVENT_DETECT)
{
if (you.skill2==1) // enemy detected
{
my.status=attacking; you.skill5 = my.skill5; }
}
}

and use the skill5 for the AI :

have the enemy now the skill5=2 search the ally with skill5=2 and attack
this one.
Posted By: MrGuest

Re: Local Pointer ! - 10/10/10 16:46

seems somewhat illogical to store an identifier on each skill,

if you need to use parent for anything else, store handles in the skills

Code:
#define ally skill5
ENTITY* get_ally(ENTITY* e){
	return(ptr_for_handle(e.ally));
}

void set_ally(ENTITY* e, ENTITY* a){
	e.ally = handle(a);
}

action ally_action(){
	set_ally(me, you); //store ally
	you = get_ally(me); //retrieve ally
}


Posted By: mEnTaL

Re: Local Pointer ! - 10/10/10 17:49

@Superku I tried ur way, but how the NPC will have its own 'target1' pointer set to the detected entity ??

@jane Your method doesn't help because all allies must be identical, only their 'target1' pointer must be set to the entity detected by their event.

@MrGuest I could be wrong, but I think you haven't understood the problem. The Ally entity has its LOCAL pointer called target1 which must point to the entity detected by the "detect_target()" event.

Posted By: Superku

Re: Local Pointer ! - 10/10/10 17:53

"@Superku I tried ur way, but how the NPC will have its own 'target1' pointer set to the detected entity ??"

?
Replace "target1" simply with "my.parent", where's the problem?
Posted By: mEnTaL

Re: Local Pointer ! - 10/10/10 18:09

Yes.. My mistake. That's exactly what I want. It works. 10x !
© 2024 lite-C Forums