Jump to content

[Tutorial] Accessing External Functions and Properties in Papyrus


Recommended Posts

Posted

Nice. I have to say, I think the #2 example on cast referencing is a lot more clear. In particular because

 

LinkedRef = GetLinkedRef() as TeleportOnBleedout

 

and

 

LinkedRef.TeleportAway()

 

is much more readable than:

 

LinkedRef = GetLinkedRef()

 

and

 

(LinkedRef as TeleportOnBleedout).TeleportAway()

 

I mean, you may as well just make the #1 case:

 

(GetLinkedRef() as TeleportOnBleedout).TeleportAway()

 

and save yourself a line of code if you're going to make it that much less readable anyway.

Posted

Thanks :)

 

I agree that it's clearer that way. I think it's easier to think of casting something to a different type as you're receiving it - when it still feels as though it could be "in flux" - than it is to think of casting it to a different type once you already have it - once it's been "set". Particularly if you're not used to the concept of casting.

 

Hopefully having all of those working examples will help anyone unfamiliar with the concept to get their head around it a little bit better.

 

Cipscis

Posted

The thing I can't wrap my head around is that warning in the wiki:

 

Be careful with variables and auto properties on scripts that are extended by other scripts - especially where some script somewhere else may have a property pointing to the base script, or trying to cast to the base script. This is because it would be possible to have two copies of a script attached to the same object, thereby creating two copies of the variable/auto property - and the other scripts that refer to the base script may randomly pick which one to talk to.

 

This is doubly-true of scripts with native functions, as the game can attach these to in-game objects at any time if it needs to, thereby creating another copy of the variable or auto property.

 

I'm not quite sure how or why this sort of thing might come up. :huh:

Posted

That's... pretty unclear. It looks as though that warning has been there since the page's first iteration, too.

 

I've added a note to the talk page about the warning. Hopefully it can be deciphered with a bit of community spirit :P

 

Cipscis

  • 4 months later...
Posted
Is there a way to actually SET a linked ref via code? I'm writing a script that creates two objects, and their scripts need to talk to each other, but for the life of me I can't figure out how.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...