ItemAttribute - jimdroberts/FishMMO GitHub Wiki

Description

Represents an attribute instance for an item, such as strength, durability, or custom stat. Holds a reference to the attribute template and its current value.


API Access

Fields

  • public int value

    The current value of this attribute instance.

Properties

  • public ItemAttributeTemplate Template { get; private set; }

    The template that defines the type and metadata of this attribute.

Methods

  • public ItemAttribute(int templateID, int value)

    Constructs an ItemAttribute from a template ID and value. Looks up the template using the provided ID. Parameters: - int templateID: The ID of the attribute template. - int value: The initial value for this attribute.*


Basic Usage

Setup

  1. Create an ItemAttribute by providing a template ID and initial value.
  2. The Template property will reference the corresponding ItemAttributeTemplate.
  3. Use the value field to store and update the attribute's current value as needed.

Example

// Example 1: Creating an item attribute instance
int templateID = 1; // Example template ID
int initialValue = 10;
ItemAttribute attr = new ItemAttribute(templateID, initialValue);

// Example 2: Accessing the template and value
ItemAttributeTemplate template = attr.Template;
int currentValue = attr.value;

Best Practices

  • Use the Template property to access metadata and configuration for the attribute.
  • Update the value field as the attribute changes during gameplay.
  • Ensure template IDs are valid and correspond to existing ItemAttributeTemplate assets.
  • Document the purpose and usage of each attribute in the template asset for clarity.
⚠️ **GitHub.com Fallback** ⚠️