Simple question: accessing mutator variable from actor

Discussions about Coding and Scripting

Simple question: accessing mutator variable from actor

Postby Aldebaran » Tue Apr 17, 2018 9:15 pm

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

Re: Simple question: accessing mutator variable from actor

Postby Feralidragon » Tue Apr 17, 2018 11:11 pm

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

Re: Simple question: accessing mutator variable from actor

Postby Aldebaran » Tue Apr 17, 2018 11:49 pm

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

Re: Simple question: accessing mutator variable from actor

Postby sektor2111 » Wed Apr 18, 2018 6:02 am

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.
User avatar
sektor2111
Godlike
 
Posts: 3496
Joined: Sun May 09, 2010 6:15 pm
Location: vect(1,1,1)

Re: Simple question: accessing mutator variable from actor

Postby Aldebaran » Wed Apr 18, 2018 12:02 pm

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


Return to Coding, Scripting

Who is online

Users browsing this forum: No registered users and 2 guests