PlayerRef = game.getplayer()... or do it in properties?

Post » Wed Jun 20, 2012 4:03 am

Thanks Cipscis, good point.

@spooky, that means you don't actually need the extra property in your magic effect script, you can just use the scriptname directly.
aadpMainQuest.DamOrKill(Damage, Target, Attacker) ; Call the global function in script aadpMainQuest.

Re: the Game.GetPlayer() discussion.
I'd say it depends on how often you're going to be using the playerRef.

Using a local as Xetrill suggested would improve the speed of many functions seen posted in this forum. ie those that call Game.GetPlayer() umpteen times within a single function or event.
There'll be a point where the speed gains of accessing a local instead of an instance variable outweigh the cost of the initial call to GetPlayer().
The other advantage of this is that a local won't stop you changing the function to a Global. So there are more potential speed savings to be had there.

I think the property should be avoided altogether. It's just the purist in me that thinks it's a waste to add a property that will never actually be accessed remotely.
If you need a PlayerRef in several locations then using a variable and an OnInit() event will give the same run-time speed as the property.
Actor PlayerRefEvent OnInit()  PlayerRef = Game.GetPlayer()EndEvent

But, if it is possible for PlayerRef to change during a game, as kuertee points out above, then the only solution is the local.
Using a local to hold Game.GetPlayer() at run-time does seem to be the most futureproof way.
Return Value:
The http://www.creationkit.com/Actor_Script that represents the player.

Imagine a new mod where you sleep then dream you are a child in a new worldspace an are represented by a new Actor.
User avatar
leigh stewart
 
Posts: 3415
Joined: Mon Oct 23, 2006 8:59 am

Post » Wed Jun 20, 2012 6:49 am

That wouldn't be an issue in this particular case, if true or not. Because the player is essentially a constant anyway.
Which makes the whole idea of binding it via a property even stranger, IMO.
Martigen, I think you're talking about this page? http://www.creationkit.com/Persistence_(Papyrus)

Cipscis
Yep Xetrill, you're right (and thanks for the link Cipscis!):

"When a script property is pointed at a reference in the editor, the target reference will be flagged as "permanently persistent". In other words, nothing you do during runtime will unload the object. This means that, if possible, you should not use properties to point at references directly. If you can, pull references in from events or other locations to avoid permanently keeping them around. Even if you reassign a value to your property while the game is running, the original reference will stick around."

Which means that Player is about the only reference it is safe to allocate via a property.

Sorry for sidetracking, back to normal programming (and interesting thread, I've learned something too).
User avatar
Emilie M
 
Posts: 3419
Joined: Fri Mar 16, 2007 9:08 am

Previous

Return to V - Skyrim