setting parent var

O Ilusionista

Captain 100K
I have an entity where I need its "parent" to receive a value from it—it's a system to control a boomerang-style projectile and track whether it's still active (since it has code to self-destruct after ricocheting a few times), and the "parent" loops until it receives that value.

Here is the code I'm using, with the problematic line commented out:
C-like:
   void self = getlocalvar("self"); // Get calling entity.
   int Bounce = getlocalvar("Bounce" + self); // Get bounced state
   void parent = getentityproperty(self, "parent"); // get parent entity
   int tControl = 0;
   //setentityvar(parent,"tControl",1);//control check
   settextobj(1, 200, 40, 1, openborconstant("FRONTPANEL_Z"), "Bounce: " + Bounce, 300+openborvariant("elapsed_time"));
   settextobj(2, 200, 50, 0, openborconstant("FRONTPANEL_Z"), "Self: " + self, 300+openborvariant("elapsed_time"));
   settextobj(3, 200, 60, 0, openborconstant("FRONTPANEL_Z"), "Parent: " + parent, 300+openborvariant("elapsed_time"));

In the image below, I can see that the code correctly identifies the entity's "parent."
1789930182654.png
(but notice that "parent" has a value, whereas "tControl" does not)

The "parent" uses this code to check the value

C-like:
    void self = getlocalvar("self");
    int tControl = getentityvar(self,"tControl");
    settextobj(10, 200, 80, 2, openborconstant("FRONTPANEL_Z"), "tControl: " + tControl, 300+openborvariant("elapsed_time"));

However, if I try to pass a value to that entity, the engine crashes with the following error:

"Script function 'setentityvar' returned an exception, check the manual for details.
parameters: <VT_EMPTY> Unitialized, "tControl", 1, "

I can't figure out what's wrong.
(I can't use a global variable like I do in the Avengers project because here you can choose the same character, and that would break the movement if two characters checked the same variable.)

--------------

EDIT:
The funny part is:
I'm checking the projectile's "owner" to determine the distance between them; if it falls below a certain value, the projectile destroys itself.
I can force the "owner" to change animations without any issues (and I could switch to "parent" instead of "owner"), but I get an error if I try to pass a variable.


C-like:
   void self = getlocalvar("self"); // Get calling entity.
   void Owner = getentityproperty(self, "owner"); // Get owner
   int x = getentityproperty(self, "x"); // Get current x coordinate
   int Ox = getentityproperty(Owner, "x"); // Get Owner's x coordinate

   if(x <= Ox + 60 && x >= Ox - 60){ // Close to owner's x?
   performattack(Owner, openborconstant("ANI_JUMP"));
   killentity(self); //Suicide!
}
 
Last edited:
I have an entity where I need its "parent" to receive a value from it—it's a system to control a boomerang-style projectile and track whether it's still active (since it has code to self-destruct after ricocheting a few times), and the "parent" loops until it receives that value.

Here is the code I'm using, with the problematic line commented out:
C-like:
   void self = getlocalvar("self"); // Get calling entity.
   int Bounce = getlocalvar("Bounce" + self); // Get bounced state
   void parent = getentityproperty(self, "parent"); // get parent entity
   int tControl = 0;
   //setentityvar(parent,"tControl",1);//control check
   settextobj(1, 200, 40, 1, openborconstant("FRONTPANEL_Z"), "Bounce: " + Bounce, 300+openborvariant("elapsed_time"));
   settextobj(2, 200, 50, 0, openborconstant("FRONTPANEL_Z"), "Self: " + self, 300+openborvariant("elapsed_time"));
   settextobj(3, 200, 60, 0, openborconstant("FRONTPANEL_Z"), "Parent: " + parent, 300+openborvariant("elapsed_time"));

In the image below, I can see that the code correctly identifies the entity's "parent."
View attachment 16047
(but notice that "parent" has a value, whereas "tControl" does not)

The "parent" uses this code to check the value

C-like:
    void self = getlocalvar("self");
    int tControl = getentityvar(self,"tControl");
    settextobj(10, 200, 80, 2, openborconstant("FRONTPANEL_Z"), "tControl: " + tControl, 300+openborvariant("elapsed_time"));

However, if I try to pass a value to that entity, the engine crashes with the following error:



I can't figure out what's wrong.
(I can't use a global variable like I do in the Avengers project because here you can choose the same character, and that would break the movement if two characters checked the same variable.)

--------------

EDIT:
The funny part is:
I'm checking the projectile's "owner" to determine the distance between them; if it falls below a certain value, the projectile destroys itself.
I can force the "owner" to change animations without any issues (and I could switch to "parent" instead of "owner"), but I get an error if I try to pass a variable.


C-like:
   void self = getlocalvar("self"); // Get calling entity.
   void Owner = getentityproperty(self, "owner"); // Get owner
   int x = getentityproperty(self, "x"); // Get current x coordinate
   int Ox = getentityproperty(Owner, "x"); // Get Owner's x coordinate

   if(x <= Ox + 60 && x >= Ox - 60){ // Close to owner's x?
   performattack(Owner, openborconstant("ANI_JUMP"));
   killentity(self); //Suicide!
}
How is the parent connection originally defined? Is it during the boomerang spawn?
 
How is the parent connection originally defined? Is it during the boomerang spawn?
My spawn01 function sets the parent


C-like:
  if (vSpawn){// safe check

    changeentityproperty(vSpawn, "position", fX, fZ, fY); //Set spawn location.
    changeentityproperty(vSpawn, "direction", iDirection); //Set direction.
    changeentityproperty(vSpawn, "parent", self); //Set parent.
    
    return vSpawn; //Return spawn.
    
  }

And I am using a shooter funciont to spawn the projectile with the desired velocity, and inside it, I set the owner too


C-like:
void shooter2(void Shot, float dx, float dy, float dz, float Vx, float Vy, float Vz)
{ // Shooting special projectile with speed control
   void self = getlocalvar("self");
   int Direction = getentityproperty(self, "direction");
   void vShot;

   if (Direction == 0){ //Is entity facing left?                 
      Vx = -Vx; //Reverse Vx direction to match facing
   }

   vShot = spawn01(Shot, dx, dy, dz);
   if (vShot){// safe check
   if(Vy < 0){changeentityproperty(vShot, "base", 0);} //APPLY DEFAULT BASE VALUE FOR DOWNWARD SHOTS
   changeentityproperty(vShot, "velocity", Vx, Vz, Vy);
   changeentityproperty(vShot, "owner", self);
   return vShot;
  }
}

as you can see on the edit part above, both PARENT and OWNER works, as I can force my parent or owner to execute a different aniamtion.
 
changeentityproperty(vSpawn, "parent", self); //Set parent.
This parent order usually allows the projectile to detect the spawner as your parent.
In case you are trying to allow the spawner to detect the projectile as a parent, I suggest inverting the order.

changeentityproperty(self, "parent", vSpawn); //Set parent.
 
But that is exactly what I want to do: the projectile must know who is it's parent
Or I am wrong?
It depends. The script below is running in which entity (in the spawner or in the projectile)?

C-like:
void self = getlocalvar("self"); // Get calling entity.
int Bounce = getlocalvar("Bounce" + self); // Get bounced state
void parent = getentityproperty(self, "parent"); // get parent entity
int tControl = 0;
//setentityvar(parent,"tControl",1);//control check
settextobj(1, 200, 40, 1, openborconstant("FRONTPANEL_Z"), "Bounce: " + Bounce, 300+openborvariant("elapsed_time"));
settextobj(2, 200, 50, 0, openborconstant("FRONTPANEL_Z"), "Self: " + self, 300+openborvariant("elapsed_time"));
settextobj(3, 200, 60, 0, openborconstant("FRONTPANEL_Z"), "Parent: " + parent, 300+openborvariant("elapsed_time"));

As a suggestion, you can define the entityvar directly in the spawn01 function. This way you can use the parent property to allow the projectile detecting his spawner, and use the entityvar to allow the spawner managing the projectile.

I have a similar check in the SOR1 Antonio boomerang, which check the distance from the spawner (Antonio boss) and change his animation in order to get it in the air.
Then, in the Antonio's @cmd spawnToss script I use the following order.

changeentityproperty(vSpawn, "parent", self);

After that, there's a boomerang's update script that gets Antonio as a parent and constantly checks his coordinates.
However, if I decide to run the update script in the Antonio boss, I would need to invert the parent order.
 
It depends. The script below is running in which entity (in the spawner or in the projectile)?
In the projectile, hence why I am getting the parent on it

As a suggestion, you can define the entityvar directly in the spawn01 function. This way you can use the parent property to allow the projectile detecting his spawner, and use the entityvar to allow the spawner managing the projectile.
But that Is what looks strange to me: why I would need to rely into a function like that if the projectile already knows who is its parent?
I can get it, I can get its position...but I can't set a variable on it?
 
But that Is what looks strange to me: why I would need to rely into a function like that if the projectile already knows who is its parent?
According to what I understood, you already are using the correct parenting order. There's some possibilities:

- you are detecting another parent, not the one desired. try to get the defaultname to confirm if it's the desired one.
- your setentityvar is running a few centiseconds before the parenting is defined, this is why it looks empty.

I still suggest defining the parent entityvar during the spawn, it's a bit safer.
 
Back
Top Bottom