Jump to content

Papyrus: Methods Vs Properties


gooser

Recommended Posts

I've seen some mod authors simply use:

Int pregnancyId = -1

Int Function GetID()
    Return pregnancyId
EndFunction

Int Function setId(Int newid)
    pregnancyId = newid
EndFunction

Instead of:

Int pregnancyId = -1

Int Property PregnancyId
   Int Function Get()
      Return pregnancyId
   EndFunction
   Function Set(Int value)
      pregnancyId = value
   EndFunction
EndProperty

Or even

String Property PregnancyId = -1 Auto

SexLab itself seems to eschew properties in favor of methods.

 

What are the advantages of using methods to wrap script variables, instead of properties wrapping fields, or auto properties?

 

Thanks!

Link to comment

I think it's a matter of preference.

1st example the property is not accesible outside the script, just the functions (encapsulation theory)

2nd and 3rd examples are the same. The auto keyword adds the get and set functions automatically.

Link to comment

Thanks I wondered. I'm experienced in C# development and properties are prevalent way to encapsulate. I wondered why SexLabFramework exposes mostly methods, not properties as an API. Are properties harder to deal with during mod upgrade vis-à-vis saved games? Would I be better off designing scripts around methods rather than properties?

Link to comment

Properties are not really the same as properties in other language. Mostly they are tied to an object outside of the script.

Defining a variable or object as property also is (currently) the only way to use them in condition functions.

Properties will be baked into the savegame and will not be removed when the script, they are attached to, is removed or the script deleted the property.

Properties are a comfortable way to access and manipulate objects from the editor (Factions, Locations, Quests etc.).

Link to comment

Okay, if I have some information in one of my scripts that needs to be accessed via other scripts, and I don't care/need to expose that information to CK, would I be better advised to expose that as property or a pair of methods?

Link to comment

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more information, see our Privacy Policy & Terms of Use