How to use 'getself' for an actor script property?

Post » Tue Jun 19, 2012 8:15 pm

I'd like to make a simple script that adjusts the health of an actor on the fly. I want it to work for any actor that spawns of the same type under a certain condition. Unfortunately I can't find a way to use 'self' in an actor script condition.

Scriptname PTAtronachAdjustScript extends ObjectReferenceActor Summonevent OnLoad();Summon = self	 ;;;; this doesn't work, so how can I get the actor that just spawned?if Summon.GetRelationshipRank(game.getplayer()) >= 1	;do stuffendifendEvent

So how would I do this?
User avatar
rolanda h
 
Posts: 3314
Joined: Tue Mar 27, 2007 9:09 pm

Post » Wed Jun 20, 2012 3:32 am

Wouldn't this work?
if Self.GetRelationshipRank(game.getplayer()) >= 1        ;do stuffendif
User avatar
Kelvin
 
Posts: 3405
Joined: Sat Nov 17, 2007 10:22 am

Post » Wed Jun 20, 2012 3:54 am

Wouldn't this work?
if Self.GetRelationshipRank(game.getplayer()) >= 1		;do stuffendif

Unfortunately not, the GetRelationshipRank function requires an actor property or the script won't compile (with 'self' it says 'GetRelationshipRank is not a function bla bla').

EDIT: I'm still unsure what exactly they mean with 'actor script' btw. In Oblivion you had references and base objects, which makes sense. In Skyrim there are references, base objects and 'actors'. Whatever that means. When I choose an actor property I still have to choose a reference, yet it is somehow different. ???
User avatar
David John Hunter
 
Posts: 3376
Joined: Sun May 13, 2007 8:24 am

Post » Wed Jun 20, 2012 10:01 am

Oh. Right. Perhaps your script needs to extent Actor then instead of ObjectReference.
User avatar
roxxii lenaghan
 
Posts: 3388
Joined: Wed Jul 05, 2006 11:53 am

Post » Tue Jun 19, 2012 7:43 pm

Uh, yeah. The new script system is quite confusing and inconvenient sometimes. Declaring it as an actor script worked and made the actor property useless. Thanks!
User avatar
City Swagga
 
Posts: 3498
Joined: Sat May 12, 2007 1:04 am

Post » Tue Jun 19, 2012 10:56 pm

Try to use the function GetActorRef
User avatar
jason worrell
 
Posts: 3345
Joined: Sat May 19, 2007 12:26 am

Post » Tue Jun 19, 2012 9:06 pm

Summon = self cant work because summon is an actor and self an objectreference. Try with summon = (self as actor)

or

if (Self as actor).GetRelationshipRank(game.getplayer()) >= 1		;do stuffendif
You could also make your script extend actor instead objectreference. (I see Arthmoore already said this)
User avatar
Latisha Fry
 
Posts: 3399
Joined: Sat Jun 24, 2006 6:42 am

Post » Wed Jun 20, 2012 3:55 am

EDIT: I'm still unsure what exactly they mean with 'actor script' btw. In Oblivion you had references and base objects, which makes sense. In Skyrim there are references, base objects and 'actors'. Whatever that means. When I choose an actor property I still have to choose a reference, yet it is somehow different. ???
Yeah, the property thing with actors is somewhat confusing because you have "Actor" which is for the reference, and "ActorBase" which is a property to point to the base actor. Which plays mind games because they labeled the base actors as "Actor" in the object window. Further confused by the fact that several functions you'd expect to only work on a base actor only work on their references, like the SetRace function that's been messing with me.
User avatar
Ridhwan Hemsome
 
Posts: 3501
Joined: Sun May 06, 2007 2:13 pm

Post » Wed Jun 20, 2012 10:51 am

Just a note - unless you need to cast "self" to a more derived type, like amgepo mentioned, or pass it as a function's parameter, you shouldn't need to use "self". For example, the following two lines of code are exactly equivalent, although I'm not sure if the compiler does enough optimisation to make them equally efficient:
self.SomeFunction()
SomeFunction

Casting "self" to a more derived type is only useful if you want to have a script attached to objects of various types in the same hierarchy, such as http://www.creationkit.com/ObjectReference_Script and http://www.creationkit.com/Actor_Script, but generally that's probably not something you'll need to do.

Cipscis
User avatar
marina
 
Posts: 3401
Joined: Tue Mar 13, 2007 10:02 pm

Post » Wed Jun 20, 2012 6:01 am

This should be your code... Change
extends ObjectReference 
to
extends Actor
:lightbulb:

Scriptname  extends Actorevent OnLoad()if self.GetRelationshipRank(game.getplayer()) >= 1	    ;do stuffendifendEvent
User avatar
Charleigh Anderson
 
Posts: 3398
Joined: Fri Feb 02, 2007 5:17 am

Post » Wed Jun 20, 2012 8:46 am

Like I just said, it's probably better not to bother with adding self. in front of function calls such as this:
ScriptName PTAtronachAdjustScript extends ActorEvent OnLoad()	If (GetRelationshipRank(Game.GetPlayer()) >= 1)		;do stuff	EndIfEndEvent
Adding superfluous code like that is rarely a good idea. If you think the code needs to be made clearer, that's where comments come in useful.

Cipscis
User avatar
JLG
 
Posts: 3364
Joined: Fri Oct 19, 2007 7:42 pm

Post » Wed Jun 20, 2012 7:20 am

Like I just said, it's probably better not to bother with adding self. in front of function calls such as this:
ScriptName PTAtronachAdjustScript extends ActorEvent OnLoad()	If (GetRelationshipRank(Game.GetPlayer()) >= 1)		;do stuff	EndIfEndEvent
Adding superfluous code like that is rarely a good idea. If you think the code needs to be made clearer, that's where comments come in useful.

Cipscis

Might be one doesn't need self... I have not thought of testing it before. However I see bethesda uses it in both the wiki and even scripts. Again I would not know why..
User avatar
phil walsh
 
Posts: 3317
Joined: Wed May 16, 2007 8:46 pm

Post » Wed Jun 20, 2012 1:07 am

If you look through Beth code you can see them using multiple if...endif blocks, all testing the same condition.
Whereas a coder would use some elseif's between.

Not all the Beth dev's are coders, so it's only natural to see that a fair bit of 'cut-n-paste' of code went on.
User avatar
Tiff Clark
 
Posts: 3297
Joined: Wed Aug 09, 2006 2:23 am

Post » Wed Jun 20, 2012 2:47 am

Might be one doesn't need self...

Cipscis is correct. You don't need self as you've used it.

Example. Here's code attached to an object placed by an explosion. It teleports the player. There are four uses of the self keyword. The only one that needs to be there is the one used inside the function call.

Scriptname TeleportScript extends ObjectReferenceActor Property playerRef AutoEvent OnInit()	self.SetMotionType( Motion_Keyframed )	RegisterForSingleUpdate( 0.5 )EndEventEvent OnUpdate()	playerRef.Moveto( Self, 0.0, 0.0, 0.0, True )	self.disable()	self.delete()endEvent

I was doing the same when i started.
User avatar
Elle H
 
Posts: 3407
Joined: Sun Aug 06, 2006 3:15 am


Return to V - Skyrim