Class PapyrusScriptAttribute
- Namespace
- SkyrimForge.Papyrus
- Assembly
- SkyrimForge.Game.dll
Marks a class whose public methods implement the native functions of the Papyrus script of the same name.
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
public sealed class PapyrusScriptAttribute : Attribute
- Inheritance
-
PapyrusScriptAttribute
- Inherited Members
Examples
[PapyrusScript]
public sealed class MyModNatives(GameTarget gameTarget)
{
public int GetPlayerGold() => gameTarget.Player.GetGoldAmount();
}
The build writes Scripts\Source\MyModNatives.psc:
Scriptname MyModNatives Hidden
int Function GetPlayerGold() global native
Remarks
The framework constructs the class as it constructs an IPlugin class, its one public constructor declaring the services it uses,
and registers each public method once the game's data has loaded. A parameter or return value is int, float, bool, string,
a form view for which Papyrus has a script type, such as Actor, or an array of one of those, and a method declaring anything else fails the build.
A method is a global native function unless its first parameter is marked PapyrusSelfAttribute.
Like an IPlugin class, the class has a log and saved state of its own, stored under its full name or the identity PluginIdentityAttribute states. An exception a method throws is written to that log, and the script receives None. A registration that fails, such as for a script whose compiled .pex is not installed, is written to that log too.
Papyrus script names share one namespace across every mod, so a class name that includes the mod's name avoids a collision with another mod's script.
The build writes the script's declarations to Scripts\Source\ClassName.psc in the project folder, for the Creation Kit's Papyrus compiler.
A function that makes the calling script wait is registered through IPapyrusFunctionRegistrar.
Constructors
PapyrusScriptAttribute()
public PapyrusScriptAttribute()
Properties
Extends
The form view whose Papyrus script type the script extends, such as ObjectReference. Null for a script that extends none.
public Type? Extends { get; init; }
Property Value
Remarks
A script that extends a form type can be attached to a form of that type,
and a method whose first parameter is marked PapyrusSelfAttribute receives that form.
A Papyrus script can also extend this one, adding the events and properties only Papyrus can declare and calling these functions on itself.
A script that extends none is declared Hidden, since it cannot be attached to a form.