Difference between revisions of "GetPlayer - Game"

From the CreationKit Wiki
Jump to navigation Jump to search
imported>Perdev
m (Undo revision 34334 by Perdev (talk))
imported>JustinOther
 
(14 intermediate revisions by 3 users not shown)
Line 21: Line 21:
Debug.Trace("Player is " + Game.GetPlayer())
Debug.Trace("Player is " + Game.GetPlayer())
</source>
</source>
== Notes ==
Use this function if you only need need to access the player '''once''' in a script. Otherwise, use an actor property named "PlayerREF" as demonstrated below since properties are literally 1,000 times faster  (See: [http://forums.bethsoft.com/topic/1360171-playerref-gamegetplayer-or-do-it-in-properties| CK Forum Thread]) than this function. The CK will auto-fill said property with the player's hardcoded reference, ACHR:00000014. While it's true that filling a property will make the reference persistent, the player (and most actors for that matter) are already necessarily persistent.
<source lang="papyrus">Actor Property PlayerRef Auto
Event OnInit()
Debug.Trace("Player is " + PlayerRef)
EndEvent</source>
In the event you are referring to the player more than once, sometimes you can minimize use of GetPlayer, utilizing an event's arguments as a free way to cache PlayerREF and in turn expedite your script.
<source lang="papyrus">Event OnActivate(ObjectReference akActionRef)
If akActionRef == Game.GetPlayer()
Int iCount = akActionRef.GetItemCount(kWidget)
If iCount
akActionRef.RemoveItem(kWidget, iCount)
akActionRef.AddItem(kBauble, iCount)
EndIf
EndIf
EndEvent</source>


== See Also ==
== See Also ==
*[[Game Script]]
*[[Game Script]]

Latest revision as of 07:10, 27 January 2013

Member of: Game Script

Obtains the actor representing the player.

Syntax[edit | edit source]

Actor Function GetPlayer() native global

Parameters[edit | edit source]

None

Return Value[edit | edit source]

The Actor that represents the player.

Examples[edit | edit source]

; Print out the player to the log
Debug.Trace("Player is " + Game.GetPlayer())

Notes[edit | edit source]

Use this function if you only need need to access the player once in a script. Otherwise, use an actor property named "PlayerREF" as demonstrated below since properties are literally 1,000 times faster (See: CK Forum Thread) than this function. The CK will auto-fill said property with the player's hardcoded reference, ACHR:00000014. While it's true that filling a property will make the reference persistent, the player (and most actors for that matter) are already necessarily persistent.

Actor Property PlayerRef Auto

Event OnInit()
	Debug.Trace("Player is " + PlayerRef)
EndEvent

In the event you are referring to the player more than once, sometimes you can minimize use of GetPlayer, utilizing an event's arguments as a free way to cache PlayerREF and in turn expedite your script.

Event OnActivate(ObjectReference akActionRef)
	If akActionRef == Game.GetPlayer()
		Int iCount = akActionRef.GetItemCount(kWidget)
		If iCount
			akActionRef.RemoveItem(kWidget, iCount)
			akActionRef.AddItem(kBauble, iCount)
		EndIf
	EndIf
EndEvent

See Also[edit | edit source]