Simple question: accessing mutator variable from actor

Discussions about Coding and Scripting
Post Reply
Aldebaran
Masterful
Posts: 672
Joined: Thu Jan 28, 2016 7:30 pm

Simple question: accessing mutator variable from actor

Post 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?
User avatar
Feralidragon
Godlike
Posts: 5489
Joined: Wed Feb 27, 2008 6:24 pm
Personal rank: Work In Progress
Location: Liandri

Re: Simple question: accessing mutator variable from actor

Post 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;
	}
}
Aldebaran
Masterful
Posts: 672
Joined: Thu Jan 28, 2016 7:30 pm

Re: Simple question: accessing mutator variable from actor

Post 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.
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Simple question: accessing mutator variable from actor

Post 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.
Aldebaran
Masterful
Posts: 672
Joined: Thu Jan 28, 2016 7:30 pm

Re: Simple question: accessing mutator variable from actor

Post 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!
Post Reply