# IHaveStats

Any object which has **Stats** should implement `IHaveStats`. Doing so will also implement [`IUseGameModules` and `IHaveGameId`](/magic-pig-games/game-modules-4/v4-migration-tips/interfaces.md).

{% hint style="success" %}
Actors which inherit [`GameModulesActor` or `GameModulesInventoryActor`](/magic-pig-games/game-modules-4/important-information/inherit-from-gamemodulesactor.md) have these methods already built in!
{% endhint %}

Below is some sample code for the required methods, which you may choose to use or modify for your purposes. Unless you are adding `Stats` that are not actors, you would not need to do any of the following, so long as you inherit `GameModulesActor` :)

<pre class="language-csharp"><code class="lang-csharp"><strong>// TryGetGameStat()
</strong><strong>public override bool TryGetGameStat(Stat stat, out GameStat gameStat) 
</strong>    => TryGetGameStat(stat.Uid(), out gameStat);
    
public override bool TryGetGameStat(string uid, out GameStat gameStat)
{
    gameStat = stats.Get(uid, false);
    return gameStat != null;
}

// GetOtherLevels()
public virtual List&#x3C;ModificationLevel> GetOtherLevels(bool cache = false)
{
    if (_modificationLevels != null &#x26;&#x26; !cache)
        return _modificationLevels;

    var otherModificationLevels = new List&#x3C;ModificationLevel>();
    
    // You would add the "Modification Levels" from other Game Module
    // objects used on this object or actor.
    otherModificationLevels.AddRange(conditions.ModificationLevels);
    otherModificationLevels.AddRange(quests.ModificationLevels);
    otherModificationLevels.AddRange(equippedItems.ModificationLevels);
    
    // This example is from DemoActor.cs in the Party Based RPG demo game
    if (!string.IsNullOrWhiteSpace(ActorRace.objectName)) 
        otherModificationLevels.Add(ActorRace.ModificationLevel);
    if (!string.IsNullOrWhiteSpace(ActorClass.objectName)) 
        otherModificationLevels.Add(ActorClass.ModificationLevel);

    _modificationLevels = otherModificationLevels;
    return otherModificationLevels;
}

// SetStatsDirty()
public virtual void SetStatsDirty(List&#x3C;Stat> statList)
{
    ResetOtherLevels(false); // Set this to cache next time it is required
    foreach (var stat in statList)
    {
        if (!TryGetGameStat(stat, out var gameStat)) continue;
        gameStat.SetDirty();
    }
}

// GetStat()
public virtual GameStat GetStat(Stat stat, bool addIfNull = true) 
    => GetStat(stat.Uid(), addIfNull);
public virtual GameStat GetStat(string uid, bool addIfNull = true) 
    => stats.Get(uid, addIfNull);
</code></pre>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://infinitypbr.gitbook.io/magic-pig-games/game-modules-4/module-documentation/stats-and-skills/ihavestats.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
