Jump to content

ObjectReference to Actor, to get for example actor values


Recommended Posts

If you need to call a function that is in the scope of the actor script on an object reference, and you know it is an actor, you just need to cast the reference as an actor, for example:

Actor theActor = ref As Actor
theActor.EnableAI(false)

Or, if you are going to use the cast only once, then you can cast it and call the function all in one, like this:

(ref As Actor).EnableAI(false)

But the function that you are looking for is GetValue, which is part of ObjectReference Script, so you can get an actor value directly from a reference.

 

PS: You can pass the actor value from an ActorValue property but, for the most common ones, you can retrieve them from functions of the game script, like Game.GetHealthAV(), so you can use them like that:

float fRefHealth = ref.GetValue(Game.GetHealthAV())
Edited by DieFeM
Link to comment
Share on other sites

Something that is often inferred but never really explained is inheritance.

 

GetValue() is an ObjectReference script function.

 

It gets the value of an ActorValue which can be attached to many base forms and all ObjectReferences ... not just actors !

 

An Actor (actually it should probably be called an ActorReference for clarity but is not) is an extension of an ObjectReference.

 

Sometimes confusing as an Actor is also a database form, but that's actually referred to as ActorBase.

 

So you can call GetValue on any ObjectReference or an Actor as it inherits from ObjectReference:

ThisObjectReference.GetValue(pHealth) 

ThisActor.GetValue(pHealth) 

(ThisActor as ObjectReference).GetValue(pHealth) 

All part of the merry confusion that is non commercial software development kits.

 

Quality test quiz question: based on this quick explainer would you infer that GetValue() can be called on an ActorBase form that has ActorValues set ?

Link to comment
Share on other sites

Excellent answers. I wondered if Papyrus had casting. Something like a reinterpret_cast or dynamic_cast in C++. Thanks for the answers and I will give the casting a try.

 

Just for your reference of my outside-of-modding experience: BSCS/MBA Professional full-stack software developer since 1994 working mostly in C++, Java, Spring, Angular.

 

Only through a good community have you guys been able to pull all this off. Thanks for that.

Edited by louisthird
Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...