# Code Examples

## Customizing periodic effects at runtime

Without modification, the periodic effects are calcuated when the [**`GameCondition`**](/magic-pig-games/game-modules-4/module-documentation/conditions/gamecondition.cs.md) object is created. If you'd like to specify the impact, you can use the `SetPeriodicEffectValue()` method.

<figure><img src="/files/IyQAwvRwlInNraM70TYt" alt=""><figcaption></figcaption></figure>

The "***Instant Health***" condition is "***Instant***", and affects the "***Health***" of the target. However, the min/max value for points are both `0`, meaning without modification, this will not have any impact at all.

The code below in `DamageActor(`) will create a new [**GameCondition**](/magic-pig-games/game-modules-4/module-documentation/conditions/gamecondition.cs.md) from the Instant Health [**Condition**](/magic-pig-games/game-modules-4/module-documentation/conditions/condition.cs.md), and then set the value using the `gameCondition.SetPeriodicEffectValue()` method, passing in the Health [**Stat**](/magic-pig-games/game-modules-4/module-documentation/stats-and-skills/stat.cs.md) object, and the min/max values.

The method will choose a random value between min and max, and assign that value to the effect, and also return the value chosen.

```csharp
public GameModulesActor actor;

// This property will return the Condition stored in _instantHealthCondition. If it
// has not yet been cached, the value will be set with the Properties lookup, and
// then returned.
public Condition InstantHealthCondition 
    => _instantHealthCondition ??= Properties.Conditions.Instant.InstantHealth;
private Condition _instantHealthCondition;
    
// A generic "Damage" method, which uses a condition called "Instant Health" which
// has one instant impact on the points of a "Health" stat, on the target actor.
public void DamageActor(float damageAmount, GameModulesActor target)
{
    // Create the GameCondition, and then set the impact
    var newGameCondition = new GameCondition(InstantHealthCondition
        , target.conditions, actor);
    var damageInflicted = newGameCondition.
        SetPeriodicEffectValue(Properties.Stats.MainStats.Health, -damageAmount
            , -damageAmount); // Method takes in a min and max; randomizes the impact

    // The method will return the final value, so you can do something with that.
    Debug.Log($"Inflicted {damageInflicted} damage to {target.GetOwnerName()}");
        
    // Don't forget to pass the GameCondition to the target!
    target.ReceiveCondition(newGameCondition);
}
```


---

# 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/conditions/code-examples.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.
