gooser Posted May 7, 2014 Posted May 7, 2014 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!
b3lisario Posted May 7, 2014 Posted May 7, 2014 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.
gooser Posted May 8, 2014 Author Posted May 8, 2014 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?
Heromaster Posted May 8, 2014 Posted May 8, 2014 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.).
Arizona_Steve Posted May 8, 2014 Posted May 8, 2014 It's more a question of whether or not the mod author wants the property to be available in the Creation Kit. Using methods is much the same as setting up a hidden property - both are available to other scripts but cannot be viewed in the Creation Kit.
Heromaster Posted May 8, 2014 Posted May 8, 2014 But Hidden Properties still can be used for Condition Functions.
gooser Posted May 8, 2014 Author Posted May 8, 2014 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?
Heromaster Posted May 8, 2014 Posted May 8, 2014 You need to know what you want to accomplish. There is no universal solution ... except 42
Recommended Posts
Archived
This topic is now archived and is closed to further replies.