Simple scripting question

Post » Tue Dec 18, 2012 11:34 pm

I'm just starting to learn how to use scripting to unlock the full potential of the CK and I'm quite a novice at it. That being said, I have a script set up where when you click a door, it teleports you somewhere else inside the same cell. Right now it works, but I have a question about it. Here's the script:


Scriptname ActivateDoorArenaScript extends ObjectReference

Door Property DoorProperty01 Auto

ObjectReference Property MoveToMarkerProperty01 Auto



Event OnActivate(ObjectReference akActionRef)
Game.GetPlayer().MoveTo( MoveToMarkerProperty01)
EndEvent

Prettty basic, but essentially the player hits the door and is moved to MarkProperty01. I'm wondering why this works though. I was under the impression that for this line of script "Event OnActivate(ObjectReference akActionRef)" I would need to specify what object will be activated, but when I put in "DoorProperty01" instead of "ObjectReference" it broke it. Is it because this line "Scriptname ActivateDoorArenaScript extends ObjectReference" basically extends the name ObjectReference onto my door automatically?

Also, what does "akActionRef" mean?

Thanks guys.
User avatar
flora
 
Posts: 3479
Joined: Fri Jun 23, 2006 1:48 am

Post » Tue Dec 18, 2012 8:42 am

When you filled MoveToMarkerProperty01, it was pointed at the ObjectReference that is the placed door which inherits the script attached to the base form, DoorProperty01. The script works 'cause it's attached to the door, so whenever it or a placed reference to it is activated, the code in its event's body will happen. The events' arguments are handled by the engine such that akActionRef will be whatever or whoever has activated the scripted object, so as it is if anyone or anything were to activate the object, the player would be moved. Replacing 'Game.GetPlayer()' with 'akActionRef' would change that so whoever or whatever activates the object would be moved. You'll not want to alter the vanilla event/function parameters. ObjectReference is a type while MoveToMarkerProperty01 is a specific form of type ObjectReference, so that's why it wouldn't compile when swapping that out.

When posting code in the forums, you'll find you can retain indentation by toggling the WYSIWYG editor in the upper leftm then pasting your code in

[spoiler][code][/code][/spoiler]

Example:
Spoiler
ScriptName ActivateDoorArenaScript Extends ObjectReferenceObjectReference Property MoveToMarkerProperty01 AutoEvent OnActivate(ObjectReference akActionRef)	If akActionRef == Game.GetPlayer() ; Is it the player who has activated the scripted object?		akActionRef.MoveTo(MoveToMarkerProperty01)	EndIfEndEvent
You'll find you'll not need the Door Property, only the ObjectReference.
User avatar
Roisan Sweeney
 
Posts: 3462
Joined: Sun Aug 13, 2006 8:28 pm

Post » Tue Dec 18, 2012 2:54 pm

Thanks for the quick response. So I don't need the Door Property because the ObjectReference property takes precedence over it because the script is attached to the door? Again, I apologize if I am asking silly questions, I am trying to build my knowledge of scripting. One more thing, when I click the door it doesn't play any sound, so I'm trying to add some sort of door opening sound to it. To do this, do I need to assign a Sound property? I was trying to add it like this:

Spoiler

I'm sure I have an issue with the syntax, which I am pulling from here http://www.creationkit.com/Play_-_Sound. Hopefully there is a simple answer to this question.
User avatar
ladyflames
 
Posts: 3355
Joined: Sat Nov 25, 2006 9:45 am

Post » Tue Dec 18, 2012 8:41 pm

You don't need the Door property 'cause you're not doing anything with the DOOR form, that is the base object that MoveToMarkerProperty01 is pointed at. You shouldn't need a sound property as you can edit your DOOR form to include sounds and then it'll happen automatically when any reference to the door is activated. Syntax, however, was right on (including implicit use of Play) if that had been necessary.

Fret not about whether questions are silly or not. We've all to start somewhere and this carp's not intuitive (at least at the onset). :)

p.s. Huzzah! That's much easier on the eyes. Thanks.
User avatar
Mr. Ray
 
Posts: 3459
Joined: Sun Jul 29, 2007 8:08 am

Post » Tue Dec 18, 2012 3:44 pm

Instead of Game.GetPlayer() use PlayerREF (with Actor Property assigned)...:D
User avatar
Isabella X
 
Posts: 3373
Joined: Sat Dec 02, 2006 3:44 am

Post » Tue Dec 18, 2012 2:48 pm

Instead of Game.GetPlayer() use PlayerREF (with Actor Property assigned)...:D
While getting to PlayerREF is literally 1,000 times faster than GetPlayer, in this case it's not crucial as timing of an OnActivate event isn't crucial. What does make sense for optimization's sake is to only check if akActionRef is the player once, then using akActionRef as a free, cached variable rather than subsequently using GetPlayer again.

Then again, if the player is referred to anywhere else in the script outside that event, I'd go with the property method.
User avatar
JUDY FIGHTS
 
Posts: 3420
Joined: Fri Jun 23, 2006 4:25 am


Return to V - Skyrim