> For the complete documentation index, see [llms.txt](https://infinitypbr.gitbook.io/magic-pig-games/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://infinitypbr.gitbook.io/magic-pig-games/game-modules-4/module-documentation/conditions/code-examples.md).

# 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);
}
```
