How Does an Attached Script Reference Its Actor

Post » Wed Jun 20, 2012 2:15 pm

I've created an Actor with an ID of "Doruul" then attached the following script:

Scriptname DoruulScript extends ObjectReference  Bool Function CustomSword()	 if (Doruul.IsEquipped(SwordProperty))		[...]	endIfendFunction

The compile fails as the "variable Doruul is undefined." Trying to call .IsEquipped off of Game.Doruul doesn't work either. So I'm wondering how I reference the instance of my Actor so I can make function calls. All of the example snippets I find seem to be player-related so they simply use 'Game.GetPlayer()' :(

TIA!
User avatar
Benito Martinez
 
Posts: 3470
Joined: Thu Aug 30, 2007 6:33 am

Post » Thu Jun 21, 2012 1:31 am

'Self' may work, but I'm not sure. One gurentee'd route you could do, is to just define an Actor property that points to your actor. Assuming he is placed somewhere in the world.
User avatar
Alisia Lisha
 
Posts: 3480
Joined: Tue Dec 05, 2006 8:52 pm

Post » Thu Jun 21, 2012 12:10 am

'Self' may work, but I'm not sure. One gurentee'd route you could do, is to just define an Actor property that points to your actor. Assuming he is placed somewhere in the world.

Thanks for the near-instant reply! I thought about Self but in this case it would refer to the actual script 'DoruulScript'.

Adding a property was pretty clever and did work! But that's kind of a work-around. I'd like to reference it "officially" if you catch my meaning.

This script is part of a base object. Wondering how to get to that object. And since it's flagged Unique, I'd also like to get it's instance.

Thinking about it some more... maybe the script isn't really attached to the Actor. Maybe the CK UI allows authors to place it there for convenience... it doesn't actually inherit or extend the Actor. Obviously I'm new to papyrus and have much more reading to do. :smile:
User avatar
carly mcdonough
 
Posts: 3402
Joined: Fri Jul 28, 2006 3:23 am

Post » Wed Jun 20, 2012 4:50 pm

A script will call its functions implicitly, so the 'Self' isn't necessary.

Self.Disable()
...and...
Disable()
...will behave identically. 'Self' is rarely needed unless passed as an argument, like
ZeldaSecretSOUN.Play(Self)
User avatar
Dewayne Quattlebaum
 
Posts: 3529
Joined: Thu Aug 30, 2007 12:29 pm

Post » Wed Jun 20, 2012 9:55 pm

Well, there ya go! Just do;

Bool Function CustomSword()
if (IsEquipped(SwordProperty))
[...]
endIf
endFunction

User avatar
Farrah Barry
 
Posts: 3523
Joined: Mon Dec 04, 2006 4:00 pm

Post » Wed Jun 20, 2012 10:49 am

Okay, that makes sense and it worked. Thanks both of you!

To get it to compile I had to change the definition to "Scriptname AenStripperScript extends Actor" which is something I think the CK should have done automatically when I created a script on the actor. Oh well. Learning. :biggrin:
User avatar
Jennifer Munroe
 
Posts: 3411
Joined: Sun Aug 26, 2007 12:57 am

Post » Wed Jun 20, 2012 3:22 pm

Okay, that makes sense and it worked. Thanks both of you!

To get it to compile I had to change the definition to "Scriptname AenStripperScript extends Actor" which is something I think the CK should have done automatically when I created a script on the actor. Oh well. Learning. :biggrin:
For future reference, when you create the script, where you type in the name before clicking OK, in that box it has a drop down menu that says "Extends" then you pick. It defaults to ObjectReference because like 95% of scripts are that. So you just change it there when creating the script. :)
User avatar
Noely Ulloa
 
Posts: 3596
Joined: Tue Jul 04, 2006 1:33 am


Return to V - Skyrim