Papyrus help: Self usage

Post » Tue Jun 19, 2012 11:04 pm

I have a script attached to an actor and I've put 4 instances of that actor in the world. Now I want to know, in the script's onPackageStart event, which one of the instances is triggering the event. I thought I'd do:

Actor Property currentActor AutoEvent...	currentActor = self

Compiling throws the error: "type mismatch while assigning to a actor (cast missing or types unrelated)"

So I tried casting, adding "as Actor" but it throws another error: "cannot cast a ScriptName to a actor, types are incompatible"

So, the self keyword is referring to the instance of the script? Is there a way to go from there and find the object that the script is running in? I already tried searching the wiki but I didn't find anything.
User avatar
Shaylee Shaw
 
Posts: 3457
Joined: Wed Feb 21, 2007 8:55 pm

Post » Tue Jun 19, 2012 7:22 pm

Update:

I got rid of the compilation errors by extending Actor on the script but if I set the Actor property to self, I get none as the value. If I show the value of self with messageBox, I get the name of the script, so I'm stuck with the same problem. I'd need a way to get the object where the script is running, which is an Actor.
User avatar
rheanna bruining
 
Posts: 3415
Joined: Fri Dec 22, 2006 11:00 am

Post » Tue Jun 19, 2012 11:24 pm

The "Self" special variable is available in non-global functions and points to the object on which the script is running as the type defined by the script. If you want to get this information as the type of object extended by this script (http://www.creationkit.com/Actor_Script, in this case) then use "Parent".

Cipscis
User avatar
Wayne W
 
Posts: 3482
Joined: Sun Jun 17, 2007 5:49 am

Post » Tue Jun 19, 2012 7:26 pm

Thanks for the help, that seems exactly what I need but I can't get it to work. Great tutorials by the way.

So, the problem is that, if I have the following, I only get an empty box.

Scriptname MyScript extends Actor	Event OnPackageStart(Package akNewPackage)		debug.messageBox(Parent)	EndEvent

Also, when loading the mod in the CK, it shows me this warning:

Failed to find variable parent used in MyScript.OnPackageStart()

Any ideas?
User avatar
Ricky Meehan
 
Posts: 3364
Joined: Wed Jun 27, 2007 5:42 pm


Return to V - Skyrim