Difference between revisions of "GetPlayer - Game"
imported>Kahmul m (→Notes) |
imported>JustinOther m (→Notes: Added arg caching example. Rearranged a notes a tad.) |
||
Line 23: | Line 23: | ||
== Notes == | == Notes == | ||
Only use this function if you need it once in a script. Otherwise use a property with the player reference as the value. A property is literally is 1000 times faster (See: [http://forums.bethsoft.com/topic/1360171-playerref-gamegetplayer-or-do-it-in-properties| CK Forum Thread]). Use the below instead, naming a property "PlayerRef". You can just auto-fill it and the player's reference will automatically be assigned. While it's true that filling a property with a reference or actor will make them persistent, the player (and most actors) are already persistent. | |||
Only use this function if you need it once in a script. Otherwise use a property with the player reference as the value | <source lang="papyrus">Actor Property PlayerRef AutoEvent OnInit() | ||
<source lang="papyrus"> | Debug.Trace("Player is " + PlayerRef) | ||
Actor Property | EndEvent</source> | ||
Debug.Trace("Player is " + | 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> | <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]] |
Revision as of 12:52, 14 January 2013
Member of: Game Script
Obtains the actor representing the player.
Syntax
Actor Function GetPlayer() native global
Parameters
None
Return Value
The Actor that represents the player.
Examples
; Print out the player to the log
Debug.Trace("Player is " + Game.GetPlayer())
Notes
Only use this function if you need it once in a script. Otherwise use a property with the player reference as the value. A property is literally is 1000 times faster (See: CK Forum Thread). Use the below instead, naming a property "PlayerRef". You can just auto-fill it and the player's reference will automatically be assigned. While it's true that filling a property with a reference or actor will make them persistent, the player (and most actors) are already persistent.
Actor Property PlayerRef AutoEvent 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