Page 1 of 1

Simple question: accessing mutator variable from actor

Posted: Tue Apr 17, 2018 9:15 pm
by Aldebaran
I have a perhaps very simple beginners question:

I have a mutator class (class XXXX extends mutator) that spawns an actor (class XXXXACT extends actor).
Now before the actor destroys itself because of no use any longer I want it to set a variable VARI in the XXXX mutator class from which it was spawned.
How can I access/set the XXXX mutator class variable VARI from the XXXXACT actor class?

Re: Simple question: accessing mutator variable from actor

Posted: Tue Apr 17, 2018 11:11 pm
by Feralidragon
First, sorry but, I just need to mention a little thing: instead of XXXX and VARI, please use something clearer next time.
For example: "MyMutator" for the mutator, "MyActor" for the actor, just "A", "SomeVar", "X", etc, for the variable, things like those, otherwise it becomes a pain to understand what you're asking (it took me a couple of rereads), and it will be also a pain for you to understand the answer.

Having that said, I will use the following in my answer:
MyMutator: your mutator class;
MyActor: your actor class;
SomeVar: your variable.

Answer:
You just need to set a back reference to the actual mutator after you spawned the actor, and then while the actor is being destroyed, the actor just needs to use that back reference to set such a variable.

For example:

Code: Select all

class MyMutator extends Mutator;

var int SomeVar;

function spawnMyActor()
{
	local MyActor a;
	
	a = spawn(class'MyActor');
	a.Mut = self;
}

Code: Select all

class MyActor extends Actor;

var MyMutator Mut;

event destroyed()
{
	super.destroyed();
	
	if (Mut != none) {
		Mut.SomeVar++;
		Mut = none;
	}
}

Re: Simple question: accessing mutator variable from actor

Posted: Tue Apr 17, 2018 11:49 pm
by Aldebaran
Oh thank you so much! You described it really in an understandable way.
Yes, sorry for my place holder names, I got a little bit rusty in programming.

Re: Simple question: accessing mutator variable from actor

Posted: Wed Apr 18, 2018 6:02 am
by sektor2111
Like I said some time ago if you take a look at UT'sstock you'll see useful things. Shortly, see Cow and BabyCow relations, that simple, and they do have a boolean involved.

Re: Simple question: accessing mutator variable from actor

Posted: Wed Apr 18, 2018 12:02 pm
by Aldebaran
I searched for "extends actor" in the entire stock code I have to find a similar class, but I found nothing.
Now I see that BabyCow uses the same mechanism I am lookinig for. Thank you for the tip!